-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_obj.go
42 lines (35 loc) · 912 Bytes
/
job_obj.go
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
package job
import (
"context"
"github.com/go-kratos/kratos/v2/log"
"github.com/google/wire"
"github.com/robfig/cron/v3"
)
var ProviderSet = wire.NewSet(NewCronJobServer)
type QyJob interface {
Handle()
Stop()
}
type QyCronJob struct {
cjs *CronJobServer
log *log.Helper
}
func NewQyCronJob(logger log.Logger,
cjs *CronJobServer) *QyCronJob {
return &QyCronJob{log: log.NewHelper(logger), cjs: cjs}
}
func (s *QyCronJob) Start(ctx context.Context) error {
log.Info("定时任务启动>>>>>>>>>>>>>")
s.cjs.Handle()
return nil
}
func (s *QyCronJob) Stop(ctx context.Context) error {
s.cjs.Stop()
log.Info("定时任务结束>>>>>>>>>>>>>")
return nil
}
func NewWithSeconds() *cron.Cron {
secondParser := cron.NewParser(cron.Second | cron.Minute |
cron.Hour | cron.Dom | cron.Month | cron.DowOptional | cron.Descriptor)
return cron.New(cron.WithParser(secondParser), cron.WithChain())
}