This commit is contained in:
parent
eae829138d
commit
6d247632b7
@ -38,6 +38,12 @@ func (c *Controller) AutoMigrate() {
|
|||||||
func (c *Controller) Run(ctx context.Context) {
|
func (c *Controller) Run(ctx context.Context) {
|
||||||
c.ctx = ctx
|
c.ctx = ctx
|
||||||
ticker := time.NewTicker(c.Interval)
|
ticker := time.NewTicker(c.Interval)
|
||||||
|
if err := c.Crawl(); err != nil {
|
||||||
|
slog.Error(err.Error())
|
||||||
|
} else {
|
||||||
|
slog.Info("抓取信息成功")
|
||||||
|
c.updateTime = time.Now()
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
@ -55,6 +61,7 @@ func (c *Controller) Run(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) Crawl() error {
|
func (c *Controller) Crawl() error {
|
||||||
|
slog.Info("开始抓取信息")
|
||||||
for page, totalPage := 1, -1; page <= totalPage || totalPage == -1; page++ {
|
for page, totalPage := 1, -1; page <= totalPage || totalPage == -1; page++ {
|
||||||
resp, err := c.client.ViewAllBags(c.ctx, page)
|
resp, err := c.client.ViewAllBags(c.ctx, page)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user