-
Notifications
You must be signed in to change notification settings - Fork 40
/
job.go
82 lines (73 loc) · 2.23 KB
/
job.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
package job
import (
"time"
"github.com/runabol/tork/clone"
"github.com/runabol/tork/task"
)
type State string
const (
Pending State = "PENDING"
Running State = "RUNNING"
Cancelled State = "CANCELLED"
Completed State = "COMPLETED"
Failed State = "FAILED"
Restart State = "RESTART"
)
type Job struct {
ID string `json:"id,omitempty"`
ParentID string `json:"parentId,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
State State `json:"state,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
StartedAt *time.Time `json:"startedAt,omitempty"`
CompletedAt *time.Time `json:"completedAt,omitempty"`
FailedAt *time.Time `json:"failedAt,omitempty"`
Tasks []*task.Task `json:"tasks"`
Execution []*task.Task `json:"execution"`
Position int `json:"position"`
Inputs map[string]string `json:"inputs,omitempty"`
Context Context `json:"context,omitempty"`
TaskCount int `json:"taskCount,omitempty"`
Output string `json:"output,omitempty"`
Result string `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
type Context struct {
Inputs map[string]string `json:"inputs,omitempty"`
Tasks map[string]string `json:"tasks,omitempty"`
}
func (j *Job) Clone() *Job {
return &Job{
ID: j.ID,
Name: j.Name,
Description: j.Description,
State: j.State,
CreatedAt: j.CreatedAt,
StartedAt: j.StartedAt,
CompletedAt: j.CompletedAt,
FailedAt: j.FailedAt,
Tasks: task.CloneTasks(j.Tasks),
Execution: task.CloneTasks(j.Execution),
Position: j.Position,
Inputs: j.Inputs,
Context: j.Context.Clone(),
ParentID: j.ParentID,
TaskCount: j.TaskCount,
Output: j.Output,
Result: j.Result,
Error: j.Error,
}
}
func (c Context) Clone() Context {
return Context{
Inputs: clone.CloneStringMap(c.Inputs),
Tasks: clone.CloneStringMap(c.Tasks),
}
}
func (c Context) AsMap() map[string]any {
return map[string]any{
"inputs": c.Inputs,
"tasks": c.Tasks,
}
}