diff --git a/pkg/database/builds.go b/pkg/database/builds.go index a77f7ec2e..fefe1e7bb 100644 --- a/pkg/database/builds.go +++ b/pkg/database/builds.go @@ -32,18 +32,11 @@ WHERE slug = ? AND commit_id = ? LIMIT 1 ` -// SQL Queries to fail all builds that are running -const buildFailStartedStmt = ` +// SQL Queries to fail all builds that are running or pending +const buildFailUnfinishedStmt = ` UPDATE builds SET status = 'Failure' -WHERE status = 'Started' -` - -// SQL Queries to fail all builds that are pending -const buildFailPendingStmt = ` -UPDATE builds -SET status = 'Failure' -WHERE status = 'Pending' +WHERE status IN ('Started', 'Pending') ` // SQL Queries to delete a Commit. @@ -84,12 +77,9 @@ func ListBuilds(id int64) ([]*Build, error) { return builds, err } +// FailUnfinishedBuilds sets status=Failure to all builds +// in the Pending and Started states func FailUnfinishedBuilds() error { - _, err := db.Exec(buildFailStartedStmt) - if err != nil { - return err - } - - _, err = db.Exec(buildFailPendingStmt) + _, err := db.Exec(buildFailUnfinishedStmt) return err } diff --git a/pkg/database/commits.go b/pkg/database/commits.go index 26c7f0fea..86a02b1cd 100644 --- a/pkg/database/commits.go +++ b/pkg/database/commits.go @@ -107,17 +107,10 @@ LIMIT 1 ` // SQL Queries to fail all commits that are currently building -const commitFailStartedStmt = ` +const commitFailUnfinishedStmt = ` UPDATE commits SET status = 'Failure' -WHERE status = 'Started' -` - -// SQL Queries to fail all commits that are currently pending -const commitFailPendingStmt = ` -UPDATE commits -SET status = 'Failure' -WHERE status = 'Started' +WHERE status IN ('Started', 'Pending') ` // Returns the Commit with the given ID. @@ -188,11 +181,6 @@ func ListBranches(repo int64) ([]*Commit, error) { } func FailUnfinishedCommits() error { - _, err := db.Exec(commitFailStartedStmt) - if err != nil { - return err - } - - _, err = db.Exec(commitFailPendingStmt) + _, err := db.Exec(commitFailUnfinishedStmt) return err }