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)