-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtask.go
35 lines (31 loc) · 823 Bytes
/
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
package gojob
import (
"github.com/google/uuid"
)
// Task is an interface that defines a task
type Task interface {
// Do starts the task, returns error if failed
// If an error is returned, the task will be retried until MaxRetries
// You can set MaxRetries by calling SetMaxRetries on the scheduler
Do() error
}
type basicTask struct {
Index int64 `json:"index"`
ID string `json:"id"`
StartedAt int64 `json:"started_at"`
FinishedAt int64 `json:"finished_at"`
NumTries int `json:"num_tries"`
Task Task `json:"task"`
Error string `json:"error"`
}
func newBasicTask(index int64, task Task) *basicTask {
return &basicTask{
Index: index,
ID: uuid.New().String(),
StartedAt: 0,
FinishedAt: 0,
NumTries: 0,
Task: task,
Error: "",
}
}