You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package crons
|
|
|
|
import (
|
|
"context"
|
|
"joybuywork/internal/app"
|
|
"joybuywork/internal/service/crons/action"
|
|
"fmt"
|
|
|
|
"github.com/robfig/cron/v3"
|
|
)
|
|
|
|
func SetUp() {
|
|
c := cron.New(
|
|
cron.WithSeconds(),
|
|
)
|
|
|
|
for t, fcs := range CronMethod() {
|
|
for _, fc := range fcs {
|
|
_, err := c.AddJob(t, fc)
|
|
if err != nil {
|
|
app.Logger.Error(context.Background(), fmt.Sprintf("定时任务启动失败: %v", err))
|
|
}
|
|
}
|
|
}
|
|
|
|
c.Start()
|
|
}
|
|
|
|
func CronMethod() map[string][]cron.Job {
|
|
return map[string][]cron.Job{
|
|
"0 * * * * *": {
|
|
action.NewJob(&action.CampaignStart{}),
|
|
action.NewJob(&action.CampaignEnd{}),
|
|
action.NewJob(&action.CampaignQuizOpen{}),
|
|
action.NewJob(&action.CampaignPreToTun{}),
|
|
},
|
|
"5 * * * * *": {
|
|
action.NewJob(&action.CampaignCancelReward{}),
|
|
action.NewJob(&action.Notify{}),
|
|
action.NewJob(&action.HeartBeatCollector{}),
|
|
},
|
|
"30 * * * * *": {
|
|
action.NewJob(&action.MallItemTask{}),
|
|
},
|
|
"0 */5 * * * *": {
|
|
action.NewJob(&action.PushNotify{}),
|
|
action.NewJob(&action.PProfCollector{}),
|
|
},
|
|
"0 */10 * * * *": {
|
|
action.NewJob(&action.CoinSceneSettlement{}),
|
|
action.NewJob(&action.ProjectUserCoinExpiredTask{}),
|
|
},
|
|
"0 */20 * * * *": {
|
|
action.NewJob(&action.StatHour{}),
|
|
action.NewJob(&action.CondHour{}),
|
|
action.NewJob(&action.AdsHour{}),
|
|
action.NewJob(&action.CampaignCoinScene{}),
|
|
action.NewJob(&action.CampaignRewardAdd{}),
|
|
},
|
|
"0 10 */3 * * *": {
|
|
action.NewJob(&action.StatDay{}),
|
|
action.NewJob(&action.CondDay{}),
|
|
action.NewJob(&action.AdsDay{}),
|
|
},
|
|
"0 20 11 * * *": {
|
|
action.NewJob(&action.SlowLog{}),
|
|
action.NewJob(&action.ErrLog{}),
|
|
action.NewJob(&action.RewardCancel{}),
|
|
},
|
|
}
|
|
}
|