From bb07b9d61b37692573d41eeb9a5c33f51b2957d9 Mon Sep 17 00:00:00 2001 From: timerzz Date: Wed, 4 Dec 2024 13:12:50 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E5=AE=9A=E6=97=B6=E6=B8=85=E7=90=86?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ats-tracer/controller.go | 15 +++++++++++++++ cmd/main.go | 1 + 2 files changed, 16 insertions(+) diff --git a/ats-tracer/controller.go b/ats-tracer/controller.go index 4d9c7c0..f09ad9b 100644 --- a/ats-tracer/controller.go +++ b/ats-tracer/controller.go @@ -61,6 +61,21 @@ func (c *Controller) Run() (err error) { } } +// 清理24小时前的ProviderAts +func (c *Controller) CleanAts() error { + ticker := time.NewTicker(24 * time.Hour) + defer ticker.Stop() + for { + select { + case <-c.ctx.Done(): + glog.Infof("cleaner退出") + return nil + case <-ticker.C: + c.storage.DB().Delete(v2.ProviderAts{}, "created_at < ?", time.Now().Add(-24*time.Hour)) + } + } +} + // 返回ready func (c *Controller) Ready() bool { return c.tracers.Ready() diff --git a/cmd/main.go b/cmd/main.go index 2d50f41..a429d3d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -83,6 +83,7 @@ func main() { wg.Go(spider.Run) wg.Go(watcher.Run) wg.Go(tracer.Run) + wg.Go(tracer.CleanAts) // http r := fiber.New(fiber.Config{ErrorHandler: web.ErrHandle})