2024-08-02 02:48:54 +00:00
|
|
|
// Task tracking
|
|
|
|
//
|
|
|
|
// Task and its associated structs implements a task tracker used to record the
|
|
|
|
// health and outcomes of individual jobs that the runner executes.
|
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gofrs/uuid"
|
|
|
|
)
|
|
|
|
|
2024-08-17 04:18:53 +00:00
|
|
|
type TaskTracker struct {
|
|
|
|
TaskId string
|
|
|
|
Status string
|
|
|
|
Error error
|
|
|
|
Parent *TaskTracker
|
|
|
|
Children []*TaskTracker
|
2024-08-02 02:48:54 +00:00
|
|
|
}
|
|
|
|
|
2024-08-17 04:18:53 +00:00
|
|
|
func NewTaskTracker(parent *TaskTracker) *TaskTracker {
|
|
|
|
newTask := &TaskTracker{TaskId: uuid.Must(uuid.NewV1()).String()}
|
2024-08-02 02:48:54 +00:00
|
|
|
|
2024-08-17 04:18:53 +00:00
|
|
|
if parent != nil {
|
|
|
|
parent.Children = append(parent.Children, newTask)
|
|
|
|
newTask.Parent = parent
|
2024-08-02 02:48:54 +00:00
|
|
|
}
|
2024-08-17 04:18:53 +00:00
|
|
|
|
|
|
|
return newTask
|
2024-08-02 02:48:54 +00:00
|
|
|
}
|
|
|
|
|
2024-08-17 04:18:53 +00:00
|
|
|
func (t *TaskTracker) SetStatus(status string) *TaskTracker {
|
|
|
|
t.Status = status
|
2024-08-02 02:48:54 +00:00
|
|
|
|
2024-08-17 04:18:53 +00:00
|
|
|
return t
|
2024-08-02 02:48:54 +00:00
|
|
|
}
|
|
|
|
|
2024-08-17 04:18:53 +00:00
|
|
|
func (t *TaskTracker) SetError(err error) *TaskTracker {
|
|
|
|
t.Error = err
|
2024-08-02 02:48:54 +00:00
|
|
|
|
2024-08-17 04:18:53 +00:00
|
|
|
return t
|
2024-08-02 02:48:54 +00:00
|
|
|
}
|
2024-08-02 20:57:56 +00:00
|
|
|
|
2024-08-17 04:18:53 +00:00
|
|
|
func (t TaskTracker) HasError() bool {
|
|
|
|
if t.Error != nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, child := range t.Children {
|
|
|
|
if child.HasError() {
|
2024-08-02 20:57:56 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
2024-08-20 03:35:33 +00:00
|
|
|
|
|
|
|
func (t TaskTracker) Failed() bool {
|
|
|
|
if t.Status == "failed" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, child := range t.Children {
|
|
|
|
if child.Failed() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|