package tasks import ( "app/commons/config" "app/commons/core" "app/tasks/period_profit" "app/tasks/quota" "github.com/robfig/cron/v3" ) func RunPeriodCron() { crontab := cron.New(cron.WithSeconds()) // 秒级定时任务 jobRule := "1 0 */2 * * *" cid, err := crontab.AddFunc(jobRule, PeriodTask) if err != nil { core.JobLog.Errorf("PeriodTask:%s", err.Error()) return } core.JobLog.Infof("PeriodTask:%s 启动成功cId:%d", jobRule, cid) crontab.Run() } func PeriodTask() { if !beginCron() { core.JobLog.Infof("corn is running...") return } defer endCron() var err error // 指标处理 err = quota.NewService().RunQuotaHandler() if err != nil { return } isTest := config.AppConf().Mod != config.ModEnvProd // 收益任务 // false 当日任务 -- 用于正式 // true 下一日任务 -- 用于手动测试 err = period_profit.NewService().RunPeriodProfit(isTest) if err != nil { return } }