also fail pending builds on startup
This commit is contained in:
parent
635b73a811
commit
138beeeb45
3 changed files with 28 additions and 4 deletions
|
@ -122,12 +122,12 @@ func setupDatabase() {
|
|||
// the drone process was shut down mid-build and thus the
|
||||
// builds will never complete.
|
||||
func discardOldBuilds() {
|
||||
err := database.FailStartedBuilds()
|
||||
err := database.FailUnfinishedBuilds()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = database.FailStartedCommits()
|
||||
err = database.FailUnfinishedCommits()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -39,6 +39,13 @@ 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'
|
||||
`
|
||||
|
||||
// SQL Queries to delete a Commit.
|
||||
const buildDeleteStmt = `
|
||||
DELETE FROM builds WHERE id = ?
|
||||
|
@ -77,7 +84,12 @@ func ListBuilds(id int64) ([]*Build, error) {
|
|||
return builds, err
|
||||
}
|
||||
|
||||
func FailStartedBuilds() error {
|
||||
func FailUnfinishedBuilds() error {
|
||||
_, err := db.Exec(buildFailStartedStmt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = db.Exec(buildFailPendingStmt)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -113,6 +113,13 @@ 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'
|
||||
`
|
||||
|
||||
// Returns the Commit with the given ID.
|
||||
func GetCommit(id int64) (*Commit, error) {
|
||||
commit := Commit{}
|
||||
|
@ -180,7 +187,12 @@ func ListBranches(repo int64) ([]*Commit, error) {
|
|||
return commits, err
|
||||
}
|
||||
|
||||
func FailStartedCommits() error {
|
||||
func FailUnfinishedCommits() error {
|
||||
_, err := db.Exec(commitFailStartedStmt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = db.Exec(commitFailPendingStmt)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue