-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtask.go
More file actions
71 lines (64 loc) · 2.13 KB
/
task.go
File metadata and controls
71 lines (64 loc) · 2.13 KB
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
package orbital
import (
"github.com/google/uuid"
)
// Possible Task status.
const (
TaskStatusCreated TaskStatus = "CREATED"
TaskStatusProcessing TaskStatus = "PROCESSING"
TaskStatusDone TaskStatus = "DONE"
TaskStatusFailed TaskStatus = "FAILED"
)
// TaskStatus represents the status of the Task.
type TaskStatus string
// Task is a trackable unit derived from the Job.
type Task struct {
ID uuid.UUID
JobID uuid.UUID
Type string
Data []byte
WorkingState []byte
LastReconciledAt int64 // The last time the task was reconciled.
ReconcileCount uint64 // The number of times the task has been reconciled.
ReconcileAfterSec uint64 // The number of seconds after which the task should be reconciled.
TotalSentCount uint64
TotalReceivedCount uint64
ETag string
Status TaskStatus
Target string
ErrorMessage string
UpdatedAt int64
CreatedAt int64
}
// TaskInfo represents the result of resolving a task.
type TaskInfo struct {
// Data contains the byte data that needs to be sent.
Data []byte
// Type specifies the type of the data.
Type string
// Targets lists the target identifiers associated with job.
Target string
}
// newTasks creates a slice of Task instances for the given job ID and task configurations.
// It returns a slice of Task, each initialized with the provided job ID and TaskInfo.
func newTasks(jobID uuid.UUID, infos []TaskInfo) []Task {
tasks := make([]Task, 0, len(infos))
for _, info := range infos {
tasks = append(tasks, newTask(jobID, info))
}
return tasks
}
// newTask creates and returns a new Task instance with the provided jobID and
// TaskInfo. It initializes the WorkingState as an empty byte slice, sets the
// ETag to a new UUID string, and assigns the TaskStatusCreated status.
func newTask(jobID uuid.UUID, info TaskInfo) Task {
return Task{
JobID: jobID,
Type: info.Type,
Data: info.Data,
WorkingState: make([]byte, 0),
ETag: uuid.NewString(),
Status: TaskStatusCreated,
Target: info.Target,
}
}