-
Notifications
You must be signed in to change notification settings - Fork 1
/
task.go
71 lines (57 loc) · 1.17 KB
/
task.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
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
// Package schedule
// file contains all struct and interface define.
package schedule
import (
"context"
"log"
"time"
)
// Task task interface for scheduler task
type Task interface {
Run(ctx context.Context)
}
// Logger logger interface for scheduler logger
type Logger interface {
Error(msg string, e any)
Debugf(msg string, n int32)
Debug(msg string)
}
// TaskFunc the function of task
type TaskFunc func(ctx context.Context)
// WhenFunc the function define of task constraint
type WhenFunc func(ctx context.Context) bool
type DefaultTask struct {
fn TaskFunc
}
func NewDefaultTask(fn TaskFunc) *DefaultTask {
return &DefaultTask{fn: fn}
}
func (d *DefaultTask) Run(ctx context.Context) {
d.fn(ctx)
}
type NextTick struct {
Year int
Month int
Day int
Hour int
Minute int
Omit bool
}
type Limit struct {
DaysOfWeek []time.Weekday
StartTime string
EndTime string
IsBetween bool
When WhenFunc
}
type DefaultLogger struct {
}
func (d *DefaultLogger) Error(msg string, r any) {
log.Println(msg, r)
}
func (d *DefaultLogger) Debug(msg string) {
log.Println(msg)
}
func (d *DefaultLogger) Debugf(msg string, i int32) {
log.Printf(msg, i)
}