mirror of
https://github.com/harness/drone.git
synced 2025-05-09 04:42:08 +08:00
also fail pending builds on startup
This commit is contained in:
parent
635b73a811
commit
138beeeb45
@ -122,12 +122,12 @@ func setupDatabase() {
|
|||||||
// the drone process was shut down mid-build and thus the
|
// the drone process was shut down mid-build and thus the
|
||||||
// builds will never complete.
|
// builds will never complete.
|
||||||
func discardOldBuilds() {
|
func discardOldBuilds() {
|
||||||
err := database.FailStartedBuilds()
|
err := database.FailUnfinishedBuilds()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = database.FailStartedCommits()
|
err = database.FailUnfinishedCommits()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,13 @@ SET status = 'Failure'
|
|||||||
WHERE status = 'Started'
|
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.
|
// SQL Queries to delete a Commit.
|
||||||
const buildDeleteStmt = `
|
const buildDeleteStmt = `
|
||||||
DELETE FROM builds WHERE id = ?
|
DELETE FROM builds WHERE id = ?
|
||||||
@ -77,7 +84,12 @@ func ListBuilds(id int64) ([]*Build, error) {
|
|||||||
return builds, err
|
return builds, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func FailStartedBuilds() error {
|
func FailUnfinishedBuilds() error {
|
||||||
_, err := db.Exec(buildFailStartedStmt)
|
_, err := db.Exec(buildFailStartedStmt)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = db.Exec(buildFailPendingStmt)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -113,6 +113,13 @@ SET status = 'Failure'
|
|||||||
WHERE status = 'Started'
|
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.
|
// Returns the Commit with the given ID.
|
||||||
func GetCommit(id int64) (*Commit, error) {
|
func GetCommit(id int64) (*Commit, error) {
|
||||||
commit := Commit{}
|
commit := Commit{}
|
||||||
@ -180,7 +187,12 @@ func ListBranches(repo int64) ([]*Commit, error) {
|
|||||||
return commits, err
|
return commits, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func FailStartedCommits() error {
|
func FailUnfinishedCommits() error {
|
||||||
_, err := db.Exec(commitFailStartedStmt)
|
_, err := db.Exec(commitFailStartedStmt)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = db.Exec(commitFailPendingStmt)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user