crontab.go
3.7 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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() {
//拉取物料数据 每4小时执行
pullMaterialK3cloud := task.NewTask("pullMaterialK3cloud", "0 0 */4 * * *", func(ctx context.Context) error {
srv := syncdata.PullDataK3CloudService{}
return srv.PullMaterialNewest()
})
task.AddTask("pullMaterialK3cloud", pullMaterialK3cloud)
//拉取物料分组数据 每4小时执行
pullMaterialGroupK3cloud := task.NewTask("pullMaterialGroupK3cloud", "0 0 */4 * * *", func(ctx context.Context) error {
srv := syncdata.PullDataK3CloudService{}
return srv.PullMaterialGroup()
})
task.AddTask("pullMaterialGroupK3cloud", pullMaterialGroupK3cloud)
//拉取订生产订单数据 每4小时执行
PullPrdMoK3cloud := task.NewTask("PullPrdMoK3cloud", "0 0 */4 * * *", func(ctx context.Context) error {
srv := syncdata.PullDataK3CloudService{}
return srv.PullPrdMoNewest()
})
task.AddTask("PullPrdMoK3cloud", PullPrdMoK3cloud)
autoInitWorkshopProductRecord := task.NewTask("AutoInitWorkshopProductRecord", "0 0 */4 * * *", AutoInitWorkshopProductRecord)
task.AddTask("AutoInitWorkshopProductRecord", autoInitWorkshopProductRecord)
autoApproveAttendanceRecord := task.NewTask("autoApproveAttendanceRecord", "0 */2 * * * *", AutoApproveProductAttendanceRecord)
task.AddTask("autoApproveAttendanceRecord", autoApproveAttendanceRecord)
autoApproveRecord := task.NewTask("autoApproveRecord", "0 */2 * * * *", AutoApproveProductRecord)
task.AddTask("autoApproveRecord", autoApproveRecord)
autoFlushDeviceDailyRunningRecord := task.NewTask("定时刷新设备每日运行记录", "0 */1 * * * *", AutoFlushDeviceDailyRunningRecord)
task.AddTask("autoFlushDeviceDailyRunningRecord", autoFlushDeviceDailyRunningRecord)
autoFlushDeviceDailyRunningRecordOEE := task.NewTask("定时刷新设备每日运行记录-OEE", "0 */10 * * * *", AutoFlushDeviceDailyRunningRecordOEE)
task.AddTask("autoFlushDeviceDailyRunningRecordOEE", autoFlushDeviceDailyRunningRecordOEE)
autoWorkshopPlanCompletionRecord := task.NewTask("定时刷新昨日车间计划完成纪录", "0 5 1-17/1 * * *", AutoWorkshopPlanCompletionRecord)
task.AddTask("autoWorkshopPlanCompletionRecord", autoWorkshopPlanCompletionRecord)
autoTodayWorkshopPlanCompletionRecord := task.NewTask("定时刷新当天车间计划完成纪录", "0 0 1-23/1 * * *", AutoTodayWorkshopPlanCompletionRecord) // 1:00, 4:00, 每三个小时运行一次
task.AddTask("autoTodayWorkshopPlanCompletionRecord", autoTodayWorkshopPlanCompletionRecord)
syncProduct := task.NewTask("定时同步产品信息", "0 0 * * * *", SyncProduct)
task.AddTask("syncProduct", syncProduct)
syncProductPlan := task.NewTask("定时同步车间计划", "0 5 * * * *", SyncProductPlan)
task.AddTask("SyncProductPlan", syncProductPlan)
syncMaterialGroup := task.NewTask("定时同步物料分组", "0 0 0/2 * * *", SyncMaterialGroup)
task.AddTask("syncMaterialGroup", syncMaterialGroup)
syncMaterial := task.NewTask("定时同步物料", "0 0 0/2 * * *", SyncMaterial)
task.AddTask("syncMaterial", syncMaterial)
}
func (crontabService *CrontabService) StartCrontabTask() {
crontabService.initTask()
task.StartTask()
log.Logger.Info("crontab start!")
}
func (crontabService *CrontabService) StopCrontabTask() {
task.StopTask()
log.Logger.Info("crontab stop!")
}