-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbreakpoint.go
109 lines (84 loc) · 2.06 KB
/
breakpoint.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package gotick
import "time"
type breakSleep struct {
Task string
RunAt time.Time
}
func (b *breakSleep) GetTask() string {
return b.Task
}
// BreakSleep means the task is exec success and sleep for d.
func BreakSleep(task string, d time.Duration) Breakpoint {
return &breakSleep{Task: task, RunAt: time.Now().Add(d)}
}
type breakDone struct {
Task string
}
func (b *breakDone) GetTask() string {
return b.Task
}
// BreakDone means the task is exec success
func BreakDone(task string) Breakpoint {
return &breakDone{Task: task}
}
type breakAbort struct {
Task string
Error error // 可以为空
}
func (b *breakAbort) GetTask() string {
return b.Task
}
// BreakAbort 终止整个 flow,err 可以为空
func BreakAbort(task string, err error) Breakpoint {
return &breakAbort{Task: task, Error: err}
}
type breakStatus struct {
Task string
}
func (b *breakStatus) GetTask() string {
return b.Task
}
type breakRetry struct {
Task string
Err error
}
// BreakRetry Abort means abort the flow
func BreakRetry(task string, err error) Breakpoint {
return &breakRetry{Task: task, Err: err}
}
func (b *breakRetry) GetTask() string {
return b.Task
}
type Breakpoint interface {
GetTask() string
}
type breakFail struct {
Task string
Err error
}
func (b *breakFail) GetTask() string {
return b.Task
}
func BreakFail(task string, err error) Breakpoint {
return &breakFail{Task: task, Err: err}
}
type breakWait struct {
RunAt time.Time
Task string
}
func (b *breakWait) GetTask() string {
return b.Task
}
// BreakWait 和 BreakSleep 的区别是 BreakSleep 只会在执行指定的 task 时才会 sleep,而 Wait 始终会 sleep。
func BreakWait(t time.Duration) Breakpoint {
return &breakWait{Task: "*", RunAt: time.Now().Add(t)} // * 表示不是针对某个 task 的断点,而是系统断点。
}
type breakContinue struct {
Task string
}
func (b *breakContinue) GetTask() string {
return b.Task
}
func BreakContinue(t time.Duration) Breakpoint {
return &breakContinue{Task: "*"} // * 表示不是针对某个 task 的断点,而是系统断点。
}