From 7a9578cd52a35e17e5a70097c60e9371acebe059 Mon Sep 17 00:00:00 2001 From: zhangwei <894646498@qq.com> Date: Tue, 11 Jun 2024 10:46:32 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=A4=9A=E4=BD=99=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: bda0bf7f31c6c6977d2c740845ddc8251f6889ee --- api/internal/cron/cron.go | 9 --------- api/internal/svc/servicecontext.go | 3 +++ api/pcm.go | 3 +++ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/api/internal/cron/cron.go b/api/internal/cron/cron.go index 00480db9..d6749e1f 100644 --- a/api/internal/cron/cron.go +++ b/api/internal/cron/cron.go @@ -20,15 +20,6 @@ import ( ) func AddCronGroup(svc *svc.ServiceContext) { - // 删除三天前的监控信息 - svc.Cron.AddFunc("0 0 0 ? * ? ", func() { - ClearMetricsData(svc) - }) - - // 同步任务信息到core端 - svc.Cron.AddFunc("*/5 * * * * ?", func() { - SyncParticipantRpc(svc) - }) svc.Cron.AddFunc("*/5 * * * * ?", func() { list, err := GetTaskList(svc) diff --git a/api/internal/svc/servicecontext.go b/api/internal/svc/servicecontext.go index 21334e33..63a1f952 100644 --- a/api/internal/svc/servicecontext.go +++ b/api/internal/svc/servicecontext.go @@ -18,6 +18,7 @@ import ( "github.com/go-redis/redis/v8" "github.com/go-resty/resty/v2" alert "github.com/prometheus/alertmanager/api/v2/client" + "github.com/robfig/cron/v3" "github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/zrpc" "gitlink.org.cn/JointCloud/pcm-ac/hpcacclient" @@ -44,6 +45,7 @@ import ( type ServiceContext struct { Config config.Config RedisClient *redis.Client + Cron *cron.Cron ModelArtsRpc modelartsservice.ModelArtsService ModelArtsImgRpc imagesservice.ImagesService DbEngin *gorm.DB @@ -123,6 +125,7 @@ func NewServiceContext(c config.Config) *ServiceContext { return &ServiceContext{ DbEngin: dbEngin, + Cron: cron.New(cron.WithSeconds()), Config: c, RedisClient: redisClient, ModelArtsRpc: modelartsservice.NewModelArtsService(zrpc.MustNewClient(c.ModelArtsRpcConf)), diff --git a/api/pcm.go b/api/pcm.go index 2dd52911..dc46d1ba 100644 --- a/api/pcm.go +++ b/api/pcm.go @@ -22,6 +22,7 @@ import ( "github.com/zeromicro/go-zero/core/service" "github.com/zeromicro/go-zero/rest" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/config" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/cron" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/mqs" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" @@ -43,6 +44,8 @@ func main() { ctx := svc.NewServiceContext(c) // start log component logx.MustSetup(c.LogConf) + ctx.Cron.Start() + cron.AddCronGroup(ctx) handler.RegisterHandlers(server, ctx) serviceGroup.Add(server)