forked from tangled.org/core
Monorepo for Tangled

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 return err 218 } 219 220 event := db.Event{ 221 Rkey: TID(), 222 Nsid: tangled.PipelineNSID,
··· 217 return err 218 } 219 220 + // do not run empty pipelines 221 + if cp.Workflows == nil { 222 + return nil 223 + } 224 + 225 event := db.Event{ 226 Rkey: TID(), 227 Nsid: tangled.PipelineNSID,
+5 -16
spindle/db/events.go
··· 86 return d.InsertEvent(event, n) 87 } 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 func (d *DB) createStatusEvent( 101 workflowId models.WorkflowId, 102 - statusKind StatusKind, 103 workflowError *string, 104 exitCode *int64, 105 n *notifier.Notifier, ··· 132 } 133 134 func (d *DB) StatusPending(workflowId models.WorkflowId, n *notifier.Notifier) error { 135 - return d.createStatusEvent(workflowId, StatusKindPending, nil, nil, n) 136 } 137 138 func (d *DB) StatusRunning(workflowId models.WorkflowId, n *notifier.Notifier) error { 139 - return d.createStatusEvent(workflowId, StatusKindRunning, nil, nil, n) 140 } 141 142 func (d *DB) StatusFailed(workflowId models.WorkflowId, workflowError string, exitCode int64, n *notifier.Notifier) error { 143 - return d.createStatusEvent(workflowId, StatusKindFailed, &workflowError, &exitCode, n) 144 } 145 146 func (d *DB) StatusSuccess(workflowId models.WorkflowId, n *notifier.Notifier) error { 147 - return d.createStatusEvent(workflowId, StatusKindSuccess, nil, nil, n) 148 }
··· 86 return d.InsertEvent(event, n) 87 } 88 89 func (d *DB) createStatusEvent( 90 workflowId models.WorkflowId, 91 + statusKind models.StatusKind, 92 workflowError *string, 93 exitCode *int64, 94 n *notifier.Notifier, ··· 121 } 122 123 func (d *DB) StatusPending(workflowId models.WorkflowId, n *notifier.Notifier) error { 124 + return d.createStatusEvent(workflowId, models.StatusKindPending, nil, nil, n) 125 } 126 127 func (d *DB) StatusRunning(workflowId models.WorkflowId, n *notifier.Notifier) error { 128 + return d.createStatusEvent(workflowId, models.StatusKindRunning, nil, nil, n) 129 } 130 131 func (d *DB) StatusFailed(workflowId models.WorkflowId, workflowError string, exitCode int64, n *notifier.Notifier) error { 132 + return d.createStatusEvent(workflowId, models.StatusKindFailed, &workflowError, &exitCode, n) 133 } 134 135 func (d *DB) StatusSuccess(workflowId models.WorkflowId, n *notifier.Notifier) error { 136 + return d.createStatusEvent(workflowId, models.StatusKindSuccess, nil, nil, n) 137 }
+3 -1
spindle/engine/engine.go
··· 127 if err != nil { 128 return err 129 } 130 } 131 132 err = e.db.StatusSuccess(wid, e.n) ··· 258 259 if state.ExitCode != 0 { 260 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) 262 } 263 } 264
··· 127 if err != nil { 128 return err 129 } 130 + 131 + return fmt.Errorf("starting steps image: %w", err) 132 } 133 134 err = e.db.StatusSuccess(wid, e.n) ··· 260 261 if state.ExitCode != 0 { 262 e.l.Error("workflow failed!", "workflow_id", wid.String(), "error", state.Error, "exit_code", state.ExitCode) 263 + return fmt.Errorf("%s", state.Error) 264 } 265 } 266
+35
spindle/models/models.go
··· 3 import ( 4 "fmt" 5 "regexp" 6 7 "tangled.sh/tangled.sh/core/api/tangled" 8 ··· 35 normalized := re.ReplaceAllString(name, "-") 36 return normalized 37 }
··· 3 import ( 4 "fmt" 5 "regexp" 6 + "slices" 7 8 "tangled.sh/tangled.sh/core/api/tangled" 9 ··· 36 normalized := re.ReplaceAllString(name, "-") 37 return normalized 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 + }