mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
mark all previously started builds as failed on startup
This commit is contained in:
parent
fb49a2c6e9
commit
635b73a811
3 changed files with 42 additions and 1 deletions
|
@ -72,6 +72,7 @@ func main() {
|
||||||
|
|
||||||
// setup database and handlers
|
// setup database and handlers
|
||||||
setupDatabase()
|
setupDatabase()
|
||||||
|
discardOldBuilds()
|
||||||
setupStatic()
|
setupStatic()
|
||||||
setupHandlers()
|
setupHandlers()
|
||||||
|
|
||||||
|
@ -116,6 +117,22 @@ func setupDatabase() {
|
||||||
migration.All().Migrate()
|
migration.All().Migrate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// discardOldBuilds sets builds that are in the 'Started'
|
||||||
|
// state to 'Failure' on startup. The assumption is that
|
||||||
|
// the drone process was shut down mid-build and thus the
|
||||||
|
// builds will never complete.
|
||||||
|
func discardOldBuilds() {
|
||||||
|
err := database.FailStartedBuilds()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = database.FailStartedCommits()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// setup routes for static assets. These assets may
|
// setup routes for static assets. These assets may
|
||||||
// be directly embedded inside the application using
|
// be directly embedded inside the application using
|
||||||
// the `rice embed` command, else they are served from disk.
|
// the `rice embed` command, else they are served from disk.
|
||||||
|
|
|
@ -32,6 +32,13 @@ WHERE slug = ? AND commit_id = ?
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// SQL Queries to fail all builds that are running
|
||||||
|
const buildFailStartedStmt = `
|
||||||
|
UPDATE builds
|
||||||
|
SET status = 'Failure'
|
||||||
|
WHERE status = 'Started'
|
||||||
|
`
|
||||||
|
|
||||||
// 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 = ?
|
||||||
|
@ -69,3 +76,8 @@ func ListBuilds(id int64) ([]*Build, error) {
|
||||||
err := meddler.QueryAll(db, &builds, buildStmt, id)
|
err := meddler.QueryAll(db, &builds, buildStmt, id)
|
||||||
return builds, err
|
return builds, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FailStartedBuilds() error {
|
||||||
|
_, err := db.Exec(buildFailStartedStmt)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
|
@ -106,6 +106,13 @@ WHERE id IN (
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// SQL Queries to fail all commits that are currently building
|
||||||
|
const commitFailStartedStmt = `
|
||||||
|
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{}
|
||||||
|
@ -172,3 +179,8 @@ func ListBranches(repo int64) ([]*Commit, error) {
|
||||||
err := meddler.QueryAll(db, &commits, commitBranchesStmt, repo)
|
err := meddler.QueryAll(db, &commits, commitBranchesStmt, repo)
|
||||||
return commits, err
|
return commits, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FailStartedCommits() error {
|
||||||
|
_, err := db.Exec(commitFailStartedStmt)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue