feat 启动时抓取一次
All checks were successful
Build image / build (push) Successful in 1m31s

This commit is contained in:
timerzz 2024-05-14 17:22:10 +08:00
parent eae829138d
commit 6d247632b7

View File

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