Monorepo for Tangled tangled.org

spindle: improve status reporting around failures

Signed-off-by: oppiliappan <me@oppi.li>

authored by oppi.li and committed by Tangled 6279659d f49efdf0

Changed files
+48 -17
knotserver
spindle
db
engine
models
+5
knotserver/internal.go
··· 217 217 return err 218 218 } 219 219 220 + // do not run empty pipelines 221 + if cp.Workflows == nil { 222 + return nil 223 + } 224 + 220 225 event := db.Event{ 221 226 Rkey: TID(), 222 227 Nsid: tangled.PipelineNSID,
+5 -16
spindle/db/events.go
··· 86 86 return d.InsertEvent(event, n) 87 87 } 88 88 89 - type StatusKind string 90 - 91 - var ( 92 - StatusKindPending StatusKind = "pending" 93 - StatusKindRunning StatusKind = "running" 94 - StatusKindFailed StatusKind = "failed" 95 - StatusKindTimeout StatusKind = "timeout" 96 - StatusKindCancelled StatusKind = "cancelled" 97 - StatusKindSuccess StatusKind = "success" 98 - ) 99 - 100 89 func (d *DB) createStatusEvent( 101 90 workflowId models.WorkflowId, 102 - statusKind StatusKind, 91 + statusKind models.StatusKind, 103 92 workflowError *string, 104 93 exitCode *int64, 105 94 n *notifier.Notifier, ··· 132 121 } 133 122 134 123 func (d *DB) StatusPending(workflowId models.WorkflowId, n *notifier.Notifier) error { 135 - return d.createStatusEvent(workflowId, StatusKindPending, nil, nil, n) 124 + return d.createStatusEvent(workflowId, models.StatusKindPending, nil, nil, n) 136 125 } 137 126 138 127 func (d *DB) StatusRunning(workflowId models.WorkflowId, n *notifier.Notifier) error { 139 - return d.createStatusEvent(workflowId, StatusKindRunning, nil, nil, n) 128 + return d.createStatusEvent(workflowId, models.StatusKindRunning, nil, nil, n) 140 129 } 141 130 142 131 func (d *DB) StatusFailed(workflowId models.WorkflowId, workflowError string, exitCode int64, n *notifier.Notifier) error { 143 - return d.createStatusEvent(workflowId, StatusKindFailed, &workflowError, &exitCode, n) 132 + return d.createStatusEvent(workflowId, models.StatusKindFailed, &workflowError, &exitCode, n) 144 133 } 145 134 146 135 func (d *DB) StatusSuccess(workflowId models.WorkflowId, n *notifier.Notifier) error { 147 - return d.createStatusEvent(workflowId, StatusKindSuccess, nil, nil, n) 136 + return d.createStatusEvent(workflowId, models.StatusKindSuccess, nil, nil, n) 148 137 }
+3 -1
spindle/engine/engine.go
··· 127 127 if err != nil { 128 128 return err 129 129 } 130 + 131 + return fmt.Errorf("starting steps image: %w", err) 130 132 } 131 133 132 134 err = e.db.StatusSuccess(wid, e.n) ··· 258 260 259 261 if state.ExitCode != 0 { 260 262 e.l.Error("workflow failed!", "workflow_id", wid.String(), "error", state.Error, "exit_code", state.ExitCode) 261 - // return e.db.MarkPipelineFailed(id, state.ExitCode, state.Error, e.n) 263 + return fmt.Errorf("%s", state.Error) 262 264 } 263 265 } 264 266
+35
spindle/models/models.go
··· 3 3 import ( 4 4 "fmt" 5 5 "regexp" 6 + "slices" 6 7 7 8 "tangled.sh/tangled.sh/core/api/tangled" 8 9 ··· 35 36 normalized := re.ReplaceAllString(name, "-") 36 37 return normalized 37 38 } 39 + 40 + type StatusKind string 41 + 42 + var ( 43 + StatusKindPending StatusKind = "pending" 44 + StatusKindRunning StatusKind = "running" 45 + StatusKindFailed StatusKind = "failed" 46 + StatusKindTimeout StatusKind = "timeout" 47 + StatusKindCancelled StatusKind = "cancelled" 48 + StatusKindSuccess StatusKind = "success" 49 + 50 + StartStates [2]StatusKind = [2]StatusKind{ 51 + StatusKindPending, 52 + StatusKindRunning, 53 + } 54 + FinishStates [4]StatusKind = [4]StatusKind{ 55 + StatusKindCancelled, 56 + StatusKindFailed, 57 + StatusKindSuccess, 58 + StatusKindTimeout, 59 + } 60 + ) 61 + 62 + func (s StatusKind) String() string { 63 + return string(s) 64 + } 65 + 66 + func (s StatusKind) IsStart() bool { 67 + return slices.Contains(StartStates[:], s) 68 + } 69 + 70 + func (s StatusKind) IsFinish() bool { 71 + return slices.Contains(FinishStates[:], s) 72 + }