combine sql statements to set both pending and started to failure on startup

This commit is contained in:
Michael Nutt 2014-04-01 15:29:14 -04:00
parent 138beeeb45
commit ce0a172136
2 changed files with 9 additions and 31 deletions

View file

@ -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
}

View file

@ -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
}