mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 11:51: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
|
||||
setupDatabase()
|
||||
discardOldBuilds()
|
||||
setupStatic()
|
||||
setupHandlers()
|
||||
|
||||
|
@ -116,6 +117,22 @@ func setupDatabase() {
|
|||
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
|
||||
// be directly embedded inside the application using
|
||||
// the `rice embed` command, else they are served from disk.
|
||||
|
|
|
@ -32,6 +32,13 @@ WHERE slug = ? AND commit_id = ?
|
|||
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.
|
||||
const buildDeleteStmt = `
|
||||
DELETE FROM builds WHERE id = ?
|
||||
|
@ -69,3 +76,8 @@ func ListBuilds(id int64) ([]*Build, error) {
|
|||
err := meddler.QueryAll(db, &builds, buildStmt, id)
|
||||
return builds, err
|
||||
}
|
||||
|
||||
func FailStartedBuilds() error {
|
||||
_, err := db.Exec(buildFailStartedStmt)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -101,11 +101,18 @@ WHERE id IN (
|
|||
SELECT MAX(id)
|
||||
FROM commits
|
||||
WHERE repo_id = ?
|
||||
AND branch = ?
|
||||
AND branch = ?
|
||||
GROUP BY branch)
|
||||
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.
|
||||
func GetCommit(id int64) (*Commit, error) {
|
||||
commit := Commit{}
|
||||
|
@ -172,3 +179,8 @@ func ListBranches(repo int64) ([]*Commit, error) {
|
|||
err := meddler.QueryAll(db, &commits, commitBranchesStmt, repo)
|
||||
return commits, err
|
||||
}
|
||||
|
||||
func FailStartedCommits() error {
|
||||
_, err := db.Exec(commitFailStartedStmt)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue