combine sql statements to set both pending and started to failure on startup
This commit is contained in:
parent
138beeeb45
commit
ce0a172136
2 changed files with 9 additions and 31 deletions
|
@ -32,18 +32,11 @@ WHERE slug = ? AND commit_id = ?
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
`
|
`
|
||||||
|
|
||||||
// SQL Queries to fail all builds that are running
|
// SQL Queries to fail all builds that are running or pending
|
||||||
const buildFailStartedStmt = `
|
const buildFailUnfinishedStmt = `
|
||||||
UPDATE builds
|
UPDATE builds
|
||||||
SET status = 'Failure'
|
SET status = 'Failure'
|
||||||
WHERE status = 'Started'
|
WHERE status IN ('Started', 'Pending')
|
||||||
`
|
|
||||||
|
|
||||||
// SQL Queries to fail all builds that are pending
|
|
||||||
const buildFailPendingStmt = `
|
|
||||||
UPDATE builds
|
|
||||||
SET status = 'Failure'
|
|
||||||
WHERE status = 'Pending'
|
|
||||||
`
|
`
|
||||||
|
|
||||||
// SQL Queries to delete a Commit.
|
// SQL Queries to delete a Commit.
|
||||||
|
@ -84,12 +77,9 @@ func ListBuilds(id int64) ([]*Build, error) {
|
||||||
return builds, err
|
return builds, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FailUnfinishedBuilds sets status=Failure to all builds
|
||||||
|
// in the Pending and Started states
|
||||||
func FailUnfinishedBuilds() error {
|
func FailUnfinishedBuilds() error {
|
||||||
_, err := db.Exec(buildFailStartedStmt)
|
_, err := db.Exec(buildFailUnfinishedStmt)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = db.Exec(buildFailPendingStmt)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,17 +107,10 @@ LIMIT 1
|
||||||
`
|
`
|
||||||
|
|
||||||
// SQL Queries to fail all commits that are currently building
|
// SQL Queries to fail all commits that are currently building
|
||||||
const commitFailStartedStmt = `
|
const commitFailUnfinishedStmt = `
|
||||||
UPDATE commits
|
UPDATE commits
|
||||||
SET status = 'Failure'
|
SET status = 'Failure'
|
||||||
WHERE status = 'Started'
|
WHERE status IN ('Started', 'Pending')
|
||||||
`
|
|
||||||
|
|
||||||
// SQL Queries to fail all commits that are currently pending
|
|
||||||
const commitFailPendingStmt = `
|
|
||||||
UPDATE commits
|
|
||||||
SET status = 'Failure'
|
|
||||||
WHERE status = 'Started'
|
|
||||||
`
|
`
|
||||||
|
|
||||||
// Returns the Commit with the given ID.
|
// Returns the Commit with the given ID.
|
||||||
|
@ -188,11 +181,6 @@ func ListBranches(repo int64) ([]*Commit, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func FailUnfinishedCommits() error {
|
func FailUnfinishedCommits() error {
|
||||||
_, err := db.Exec(commitFailStartedStmt)
|
_, err := db.Exec(commitFailUnfinishedStmt)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = db.Exec(commitFailPendingStmt)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue