Skip to content

Commit

Permalink
FIX: allow first time no status
Browse files Browse the repository at this point in the history
  • Loading branch information
JanuszCzornik committed Jan 31, 2024
1 parent e563208 commit b5000f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions persistent/workflows/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ func UpdateStatus(db *sql.DB, workflow int64, status string) error {
return err
}

func GetLastStatus(db *sql.DB, name string) (string, error) {
var status string
func GetLastStatus(db *sql.DB, name string) (*string, error) {
var status *string

row := db.QueryRow("SELECT status FROM workflows WHERE name = ? ORDER BY id DESC LIMIT 1", name)
if err := row.Scan(&status); err != nil {
if err := row.Scan(&status); err != sql.ErrNoRows && err != nil {
return status, err
}

Expand Down
13 changes: 8 additions & 5 deletions workflow/pworkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ type PWorkflow struct {
db persistent.DBClient
}

func checkIfLastFailed(db *sql.DB, name string) (bool, error) {
func checkIfCanCreate(db *sql.DB, name string) (bool, error) {
status, err := workflows.GetLastStatus(db, name)
if err != nil {
return true, err
}

log.Printf("Last status for %s is %s\n", name, status)
return (status == workflows.FailedRollbackStatus), nil
if status == nil {
return false, nil
}

return (*status == workflows.FinishedStatus || *status == workflows.RollbackedStatus), nil
}

func NewPWorkflow(name string, tasks []task, client persistent.DBClient) (PWorkflow, error) {
Expand All @@ -33,12 +36,12 @@ func NewPWorkflow(name string, tasks []task, client persistent.DBClient) (PWorkf
}
defer db.Close()

lastFailed, err := checkIfLastFailed(db, name)
canCreate, err := checkIfCanCreate(db, name)
if err != nil {
return PWorkflow{}, err
}

if lastFailed == true {
if canCreate == false {
return PWorkflow{}, errors.New(fmt.Sprintf("Cannot create new workflow %s. Last workflow failed to rollback", name))
}

Expand Down

0 comments on commit b5000f5

Please sign in to comment.