Skip to content

Commit

Permalink
chore: support playbook action failures without errors
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Sep 4, 2024
1 parent 92e292b commit e07c3af
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions models/playbooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,19 +420,24 @@ func (p PlaybookRunAction) Start(db *gorm.DB) error {
}

func (p PlaybookRunAction) Fail(db *gorm.DB, result any, err error) error {
if o, ok := oops.AsOops(err); ok {
result = map[string]any{
"result": result,
"error": o.ToMap(),
}
}
if err := p.Update(db, map[string]any{
"error": err.Error(),
updates := map[string]any{
"result": marshallResult(result),
"start_time": gorm.Expr("CASE WHEN start_time IS NULL THEN CLOCK_TIMESTAMP() ELSE start_time END"),
"end_time": gorm.Expr("CLOCK_TIMESTAMP()"),
"status": PlaybookActionStatusFailed,
}); err != nil {
}

if err != nil {
if o, ok := oops.AsOops(err); ok {
updates["result"] = map[string]any{
"result": result,
"error": o.ToMap(),
}
}
updates["error"] = err.Error()
}

if err := p.Update(db, updates); err != nil {
return err
}

Expand Down

0 comments on commit e07c3af

Please sign in to comment.