diff --git a/db/playbooks.go b/db/playbooks.go index 4b6ef9a3..6fd5a73e 100644 --- a/db/playbooks.go +++ b/db/playbooks.go @@ -247,7 +247,7 @@ func UpdatePlaybookRunStatusIfApproved(ctx context.Context, playbookID string, a SELECT run_id FROM run_approvals WHERE approvers %s (SELECT array_agg(id) FROM allowed_approvers) )`, operator) - tx := ctx.DB().Exec(query, approval.Approvers.Teams, approval.Approvers.People, models.PlaybookRunStatusScheduled, models.PlaybookRunStatusPending, playbookID) + tx := ctx.DB().Exec(query, approval.Approvers.Teams, approval.Approvers.People, models.PlaybookRunStatusScheduled, models.PlaybookRunStatusPendingApproval, playbookID) if tx.RowsAffected > 0 { ctx.Tracef("[%s] %d playbook runs approved", playbookID, tx.RowsAffected) } diff --git a/go.mod b/go.mod index de73853f..6ca873de 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/containrrr/shoutrrr v0.8.0 github.com/fergusstrange/embedded-postgres v1.25.0 // indirect github.com/flanksource/commons v1.29.10 - github.com/flanksource/duty v1.0.707 + github.com/flanksource/duty v1.0.708 github.com/flanksource/gomplate/v3 v3.24.35 github.com/flanksource/kopper v1.0.10 github.com/gomarkdown/markdown v0.0.0-20240419095408-642f0ee99ae2 diff --git a/go.sum b/go.sum index e41d5387..54978007 100644 --- a/go.sum +++ b/go.sum @@ -877,8 +877,8 @@ github.com/flanksource/artifacts v1.0.14 h1:Vv70bccsae0MwGaf/uSPp34J5V1/PyKfct9z github.com/flanksource/artifacts v1.0.14/go.mod h1:qHVCnQu5k50aWNJ5UhpcAKEl7pAzqUrFFKGSm147G70= github.com/flanksource/commons v1.29.10 h1:T/S95Pl8kASEFvQjQ7fJjTUqeVdhxQXg1vfkULTYFJQ= github.com/flanksource/commons v1.29.10/go.mod h1:iTbrXOSp3Spv570Nly97D/U9cQjLZoVlmWCXqWzsvRU= -github.com/flanksource/duty v1.0.707 h1:cFhPHVVEaFdy7/+U3u7QY9LUaK6FEuqQ7pa1HHyL9AU= -github.com/flanksource/duty v1.0.707/go.mod h1:4ZNkZ3n0Vtx+wqQoto36Z139U9TBWlCYEpAwuqZiCQk= +github.com/flanksource/duty v1.0.708 h1:TukO3jOk7z1m5+Wu1jf9k60f9yOwxzPGCjPFl3sZHk8= +github.com/flanksource/duty v1.0.708/go.mod h1:4ZNkZ3n0Vtx+wqQoto36Z139U9TBWlCYEpAwuqZiCQk= github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc= github.com/flanksource/gomplate/v3 v3.24.35 h1:6grps46JjAQI7haaGbiJXDQb6qxat0Ra9EN99iaBHVQ= github.com/flanksource/gomplate/v3 v3.24.35/go.mod h1:W/jhtuxSmCVFZibf11qJOSceEq++DEL0eCj/F0Y+zVY= diff --git a/playbook/events.go b/playbook/events.go index 2b71e78e..d13c023f 100644 --- a/playbook/events.go +++ b/playbook/events.go @@ -1,12 +1,11 @@ package playbook import ( - "fmt" - "time" - "encoding/json" + "fmt" "strconv" "strings" + "time" "github.com/flanksource/commons/collections" "github.com/flanksource/commons/logger" @@ -174,12 +173,12 @@ func (t *playbookScheduler) Handle(ctx context.Context, event models.Event) erro run := models.PlaybookRun{ PlaybookID: p.ID, - Status: models.PlaybookRunStatusPending, + Status: models.PlaybookRunStatusScheduled, Spec: p.Spec, } - if playbook.Spec.Approval == nil || playbook.Spec.Approval.Approvers.Empty() { - run.Status = models.PlaybookRunStatusScheduled + if playbook.Spec.Approval != nil && !playbook.Spec.Approval.Approvers.Empty() { + run.Status = models.PlaybookRunStatusPendingApproval } switch specEvent.Class { @@ -294,7 +293,7 @@ func onPlaybookRunNewApproval(ctx context.Context, event models.Event) error { return err } - if run.Status != models.PlaybookRunStatusPending { + if run.Status != models.PlaybookRunStatusPendingApproval { return nil } diff --git a/playbook/playbook.go b/playbook/playbook.go index 14ed58f3..873118e8 100644 --- a/playbook/playbook.go +++ b/playbook/playbook.go @@ -34,7 +34,7 @@ type PlaybookSummary struct { } func GetPlaybookStatus(ctx context.Context, runId uuid.UUID) (PlaybookSummary, error) { - var summary = PlaybookSummary{} + summary := PlaybookSummary{} run, err := models.PlaybookRun{ID: runId}.Load(ctx.DB()) if err != nil { return summary, err @@ -88,7 +88,7 @@ func Run(ctx context.Context, playbook *models.Playbook, req RunParams) (*models run := models.PlaybookRun{ PlaybookID: playbook.ID, - Status: models.PlaybookRunStatusPending, + Status: models.PlaybookRunStatusScheduled, Parameters: req.Params, AgentID: req.AgentID, } @@ -101,8 +101,8 @@ func Run(ctx context.Context, playbook *models.Playbook, req RunParams) (*models run.CreatedBy = &ctx.User().ID } - if spec.Approval == nil || spec.Approval.Approvers.Empty() { - run.Status = models.PlaybookRunStatusScheduled + if spec.Approval != nil && !spec.Approval.Approvers.Empty() { + run.Status = models.PlaybookRunStatusPendingApproval } if req.ComponentID != nil {