diff --git a/cmd/droned/drone.go b/cmd/droned/drone.go index e8d0e2ab6..1087fbed4 100644 --- a/cmd/droned/drone.go +++ b/cmd/droned/drone.go @@ -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) } diff --git a/pkg/database/builds.go b/pkg/database/builds.go index c589b625c..a77f7ec2e 100644 --- a/pkg/database/builds.go +++ b/pkg/database/builds.go @@ -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 } diff --git a/pkg/database/commits.go b/pkg/database/commits.go index b58f3f8d9..26c7f0fea 100644 --- a/pkg/database/commits.go +++ b/pkg/database/commits.go @@ -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 }