-
Notifications
You must be signed in to change notification settings - Fork 5
/
task.go
47 lines (42 loc) · 1.38 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
package task
type Task interface {
Execute() error
CallBack(result *Result)
}
// task is used in the project
type task struct {
attemptCount int // 尝试次数
maxRetryTimes int // 最大尝试次数
baseRetryBackOffMs int64 // 首次重试的退避时间
maxRetryIntervalInMs int64 // 重试的最大退避时间,默认为 50 秒
createTimeMs int64 // 创建的时间
nextRetryMs int64 // 下次重试的时间
result *Result // 发送结果
task Task
}
// *************************
// task factory
type taskFactory struct {
maxRetryTimes int // 最大尝试次数
baseRetryBackOffMs int64 // 首次重试的退避时间
maxRetryIntervalInMs int64 // 重试的最大退避时间,默认为 50 秒
}
func newTaskFactory(c *Config) *taskFactory {
return &taskFactory{
maxRetryTimes: c.MaxRetryTimes,
baseRetryBackOffMs: c.BaseRetryBackOffMs,
maxRetryIntervalInMs: c.MaxRetryBackOffMs,
}
}
func (taskFactory *taskFactory) produce(t Task) *task {
return &task{
attemptCount: 0,
maxRetryTimes: taskFactory.maxRetryTimes,
baseRetryBackOffMs: taskFactory.baseRetryBackOffMs,
maxRetryIntervalInMs: taskFactory.maxRetryIntervalInMs,
createTimeMs: getTimeMs(),
nextRetryMs: 0,
result: initResult(t),
task: t,
}
}