From ab83eb53b1a7d25b9605fcc116618abfe744aa4e Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Wed, 18 Jun 2025 11:14:07 +0100 Subject: [PATCH] spindle: improve status reporting around failures Change-Id: rqtksnwyyqwnqwsuprszmtntmnpnrlxv Signed-off-by: oppiliappan --- knotserver/internal.go | 5 +++++ spindle/db/events.go | 21 +++++---------------- spindle/engine/engine.go | 4 +++- spindle/models/models.go | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/knotserver/internal.go b/knotserver/internal.go index ab8749f..e9873f6 100644 --- a/knotserver/internal.go +++ b/knotserver/internal.go @@ -217,6 +217,11 @@ func (h *InternalHandle) triggerPipeline(line git.PostReceiveLine, gitUserDid, r return err } + // do not run empty pipelines + if cp.Workflows == nil { + return nil + } + event := db.Event{ Rkey: TID(), Nsid: tangled.PipelineNSID, diff --git a/spindle/db/events.go b/spindle/db/events.go index c927723..7a59759 100644 --- a/spindle/db/events.go +++ b/spindle/db/events.go @@ -86,20 +86,9 @@ func (d *DB) CreateStatusEvent(rkey string, s tangled.PipelineStatus, n *notifie return d.InsertEvent(event, n) } -type StatusKind string - -var ( - StatusKindPending StatusKind = "pending" - StatusKindRunning StatusKind = "running" - StatusKindFailed StatusKind = "failed" - StatusKindTimeout StatusKind = "timeout" - StatusKindCancelled StatusKind = "cancelled" - StatusKindSuccess StatusKind = "success" -) - func (d *DB) createStatusEvent( workflowId models.WorkflowId, - statusKind StatusKind, + statusKind models.StatusKind, workflowError *string, exitCode *int64, n *notifier.Notifier, @@ -132,17 +121,17 @@ func (d *DB) createStatusEvent( } func (d *DB) StatusPending(workflowId models.WorkflowId, n *notifier.Notifier) error { - return d.createStatusEvent(workflowId, StatusKindPending, nil, nil, n) + return d.createStatusEvent(workflowId, models.StatusKindPending, nil, nil, n) } func (d *DB) StatusRunning(workflowId models.WorkflowId, n *notifier.Notifier) error { - return d.createStatusEvent(workflowId, StatusKindRunning, nil, nil, n) + return d.createStatusEvent(workflowId, models.StatusKindRunning, nil, nil, n) } func (d *DB) StatusFailed(workflowId models.WorkflowId, workflowError string, exitCode int64, n *notifier.Notifier) error { - return d.createStatusEvent(workflowId, StatusKindFailed, &workflowError, &exitCode, n) + return d.createStatusEvent(workflowId, models.StatusKindFailed, &workflowError, &exitCode, n) } func (d *DB) StatusSuccess(workflowId models.WorkflowId, n *notifier.Notifier) error { - return d.createStatusEvent(workflowId, StatusKindSuccess, nil, nil, n) + return d.createStatusEvent(workflowId, models.StatusKindSuccess, nil, nil, n) } diff --git a/spindle/engine/engine.go b/spindle/engine/engine.go index b3c04a9..dd2311e 100644 --- a/spindle/engine/engine.go +++ b/spindle/engine/engine.go @@ -127,6 +127,8 @@ func (e *Engine) StartWorkflows(ctx context.Context, pipeline *tangled.Pipeline, if err != nil { return err } + + return fmt.Errorf("starting steps image: %w", err) } err = e.db.StatusSuccess(wid, e.n) @@ -258,7 +260,7 @@ func (e *Engine) StartSteps(ctx context.Context, steps []*tangled.Pipeline_Step, if state.ExitCode != 0 { e.l.Error("workflow failed!", "workflow_id", wid.String(), "error", state.Error, "exit_code", state.ExitCode) - // return e.db.MarkPipelineFailed(id, state.ExitCode, state.Error, e.n) + return fmt.Errorf("%s", state.Error) } } diff --git a/spindle/models/models.go b/spindle/models/models.go index 84abc45..32065e8 100644 --- a/spindle/models/models.go +++ b/spindle/models/models.go @@ -3,6 +3,7 @@ package models import ( "fmt" "regexp" + "slices" "tangled.sh/tangled.sh/core/api/tangled" @@ -35,3 +36,37 @@ func normalize(name string) string { normalized := re.ReplaceAllString(name, "-") return normalized } + +type StatusKind string + +var ( + StatusKindPending StatusKind = "pending" + StatusKindRunning StatusKind = "running" + StatusKindFailed StatusKind = "failed" + StatusKindTimeout StatusKind = "timeout" + StatusKindCancelled StatusKind = "cancelled" + StatusKindSuccess StatusKind = "success" + + StartStates [2]StatusKind = [2]StatusKind{ + StatusKindPending, + StatusKindRunning, + } + FinishStates [4]StatusKind = [4]StatusKind{ + StatusKindCancelled, + StatusKindFailed, + StatusKindSuccess, + StatusKindTimeout, + } +) + +func (s StatusKind) String() string { + return string(s) +} + +func (s StatusKind) IsStart() bool { + return slices.Contains(StartStates[:], s) +} + +func (s StatusKind) IsFinish() bool { + return slices.Contains(FinishStates[:], s) +} -- 2.43.0