-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtask.go
59 lines (50 loc) · 1.26 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
package timing
import (
"time"
"github.com/google/uuid"
"fmt"
)
//need to do task has interface Job
type Task struct {
Job Job
Uuid string
RunTime int64 //UnixNanoTime
Spacing int64 //spacing second
EndTime int64 //UnixNanoTime
Number int //exec number
}
//callback function has interface Job
type FuncJob func()
func (f FuncJob) Run() { f() }
type Job interface {
Run()
}
func getTaskWithFunc(unixTime int64, f func()) *Task {
return &Task{
Job: FuncJob(f),
RunTime: unixTime,
Uuid: uuid.New().String(),
}
}
func getTaskWithFuncSpacingNumber(spacing int64, number int, f func()) *Task {
return &Task{
Job: FuncJob(f),
RunTime: time.Now().UnixNano()+spacing,
Spacing: spacing,
Number: number,
EndTime: time.Now().UnixNano()+ int64(number)*spacing*int64(time.Second),
Uuid: uuid.New().String(),
}
}
func getTaskWithFuncSpacing(spacing int64, endTime int64, f func()) *Task {
return &Task{
Job: FuncJob(f),
RunTime: time.Now().UnixNano()+ int64(time.Second)*spacing,
Spacing: spacing,
EndTime: endTime,
Uuid: uuid.New().String(),
}
}
func (task *Task) toString() string {
return fmt.Sprintf("uuid: %s, runTime %d, spaceing %d, endTime %d, number %d",task.Uuid,task.RunTime,task.Spacing,task.EndTime,task.Number)
}