crontab.go
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package crontab
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
"github.com/beego/beego/v2/task"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/application/syncdata"
)
type CrontabService struct {
}
func NewCrontabService(options map[string]interface{}) *CrontabService {
newCrontabService := &CrontabService{}
return newCrontabService
}
func (crontabService *CrontabService) initTask() {
//PullDataK3Cloud 晚上0时10分执行
pullMaterialK3cloud := task.NewTask("pullMaterialK3cloud", "0 10 0 * * *", func(ctx context.Context) error {
srv := syncdata.PullDataK3CloudService{}
return srv.PullMaterialNewest()
})
task.AddTask("pullMaterialK3cloud", pullMaterialK3cloud)
//PullDataK3Cloud 晚上0时10分执行
pullMaterialGroupK3cloud := task.NewTask("pullMaterialGroupK3cloud", "0 10 0 * * *", func(ctx context.Context) error {
srv := syncdata.PullDataK3CloudService{}
return srv.PullMaterialGroup()
})
task.AddTask("pullMaterialGroupK3cloud", pullMaterialGroupK3cloud)
}
func (crontabService *CrontabService) StartCrontabTask() {
crontabService.initTask()
task.StartTask()
log.Logger.Info("crontab start!")
}
func (crontabService *CrontabService) StopCrontabTask() {
task.StopTask()
log.Logger.Info("crontab stop!")
}