68 lines
1.1 KiB
Go
68 lines
1.1 KiB
Go
// 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"
|
|
)
|
|
|
|
type TaskTracker struct {
|
|
TaskId string
|
|
Status string
|
|
Error error
|
|
Parent *TaskTracker
|
|
Children []*TaskTracker
|
|
}
|
|
|
|
func NewTaskTracker(parent *TaskTracker) *TaskTracker {
|
|
newTask := &TaskTracker{TaskId: uuid.Must(uuid.NewV1()).String()}
|
|
|
|
if parent != nil {
|
|
parent.Children = append(parent.Children, newTask)
|
|
newTask.Parent = parent
|
|
}
|
|
|
|
return newTask
|
|
}
|
|
|
|
func (t *TaskTracker) SetStatus(status string) *TaskTracker {
|
|
t.Status = status
|
|
|
|
return t
|
|
}
|
|
|
|
func (t *TaskTracker) SetError(err error) *TaskTracker {
|
|
t.Error = err
|
|
|
|
return t
|
|
}
|
|
|
|
func (t TaskTracker) HasError() bool {
|
|
if t.Error != nil {
|
|
return true
|
|
}
|
|
|
|
for _, child := range t.Children {
|
|
if child.HasError() {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (t TaskTracker) Failed() bool {
|
|
if t.Status == "failed" {
|
|
return true
|
|
}
|
|
|
|
for _, child := range t.Children {
|
|
if child.Failed() {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|