feat: use run id and job id in page view

This commit is contained in:
Jason Song
2022-10-14 18:30:00 +08:00
parent d320eb66f4
commit 1cba52376a
5 changed files with 126 additions and 96 deletions

View File

@ -69,6 +69,40 @@ func (task *Task) LoadAttributes(ctx context.Context) error {
return nil
}
// FullSteps returns steps with "Set up job" and "Complete job"
func (task *Task) FullSteps() []*TaskStep {
var firstStep, lastStep *TaskStep
if l := len(task.Steps); l > 0 {
firstStep = task.Steps[0]
lastStep = task.Steps[l-1]
}
headStep := &TaskStep{
Name: "Set up job",
LogIndex: 0,
LogLength: -1, // no limit
Started: task.Started,
}
if firstStep != nil {
headStep.LogLength = firstStep.LogIndex
headStep.Stopped = firstStep.Started
}
tailStep := &TaskStep{
Name: "Complete job",
Stopped: task.Stopped,
}
if lastStep != nil {
tailStep.LogIndex = lastStep.LogIndex + lastStep.LogLength
tailStep.LogLength = -1 // no limit
tailStep.Started = lastStep.Stopped
}
steps := make([]*TaskStep, 0, len(task.Steps)+2)
steps = append(steps, headStep)
steps = append(steps, task.Steps...)
steps = append(steps, tailStep)
return steps
}
// ErrTaskNotExist represents an error for bot task not exist
type ErrTaskNotExist struct {
ID int64