forked from pardnchiu/go-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype.go
More file actions
75 lines (62 loc) · 1.19 KB
/
Copy pathtype.go
File metadata and controls
75 lines (62 loc) · 1.19 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
package cron
import (
"sync"
"time"
goLogger "github.com/pardnchiu/go-logger"
)
const (
defaultLogPath = "./logs/cron.log"
defaultLogMaxSize = 16 * 1024 * 1024
defaultLogMaxBackup = 5
)
type Log = goLogger.Log
type Logger = goLogger.Logger
type Config struct {
Log *Log
Location *time.Location
}
type cron struct {
logger *Logger
mutex sync.Mutex
wait sync.WaitGroup
heap taskHeap
chain taskChain
parser parser
stop chan struct{}
add chan *task
remove chan int64
removeAll chan struct{}
location *time.Location
next int64
running bool
}
type task struct {
ID int64
Description string
Schedule schedule
Action func()
Next time.Time
Prev time.Time
Enable bool
}
type schedule interface {
next(time.Time) time.Time
}
type scheduleResult struct {
minute,
hour,
dom,
month,
dow scheduleField
}
type scheduleField struct {
Value int // 具體數值
All bool // 是否匹配所有值(對應 "*")
Step int // 步長值(對應 "*/n")
}
type delayScheduleResult struct {
delay time.Duration
}
type taskHeap []*task
type taskChain []func(func()) func()
type parser struct{}