Implement resume, skip, and stage selection
This commit is contained in:
51
internal/app/run_control.go
Normal file
51
internal/app/run_control.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
||||
)
|
||||
|
||||
type stageAction string
|
||||
|
||||
const (
|
||||
stageActionRun stageAction = "run"
|
||||
stageActionSkip stageAction = "skip"
|
||||
)
|
||||
|
||||
type stageDecision struct {
|
||||
Stage stage.Stage
|
||||
Action stageAction
|
||||
}
|
||||
|
||||
func decideStageActions(stages []stage.Stage, m *manifest.Manifest, force bool) []stageDecision {
|
||||
out := make([]stageDecision, 0, len(stages))
|
||||
for _, s := range stages {
|
||||
action := stageActionRun
|
||||
// TODO: incorporate stale detection once checksum/input change tracking is implemented.
|
||||
if !force && stageSucceeded(m, s.Name()) {
|
||||
action = stageActionSkip
|
||||
}
|
||||
out = append(out, stageDecision{
|
||||
Stage: s,
|
||||
Action: action,
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func stageSucceeded(m *manifest.Manifest, name string) bool {
|
||||
if m == nil || m.Stages == nil {
|
||||
return false
|
||||
}
|
||||
sr := m.Stages[name]
|
||||
return sr != nil && sr.Status == manifest.StatusSucceeded
|
||||
}
|
||||
|
||||
func firstNonSucceededIndex(stages []stage.Stage, m *manifest.Manifest) int {
|
||||
for i, s := range stages {
|
||||
if !stageSucceeded(m, s.Name()) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return len(stages)
|
||||
}
|
||||
Reference in New Issue
Block a user