mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-23 10:21:00 +00:00
Merge pull request #213 from movableink/fail-pending-on-startup
Fail pending on startup
This commit is contained in:
commit
dd46fa9563
3 changed files with 44 additions and 1 deletions
|
@ -64,6 +64,7 @@ func main() {
|
||||||
if err := database.Init(driver, datasource); err != nil {
|
if err := database.Init(driver, datasource); err != nil {
|
||||||
log.Fatal("Can't initialize database: ", err)
|
log.Fatal("Can't initialize database: ", err)
|
||||||
}
|
}
|
||||||
|
discardOldBuilds()
|
||||||
setupStatic()
|
setupStatic()
|
||||||
setupHandlers()
|
setupHandlers()
|
||||||
|
|
||||||
|
@ -89,6 +90,22 @@ func checkTLSFlags() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.FailUnfinishedBuilds()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = database.FailUnfinishedCommits()
|
||||||
|
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 or pending
|
||||||
|
const buildFailUnfinishedStmt = `
|
||||||
|
UPDATE builds
|
||||||
|
SET status = 'Failure'
|
||||||
|
WHERE status IN ('Started', '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 = ?
|
||||||
|
@ -69,3 +76,10 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FailUnfinishedBuilds sets status=Failure to all builds
|
||||||
|
// in the Pending and Started states
|
||||||
|
func FailUnfinishedBuilds() error {
|
||||||
|
_, err := db.Exec(buildFailUnfinishedStmt)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
|
@ -101,11 +101,18 @@ WHERE id IN (
|
||||||
SELECT MAX(id)
|
SELECT MAX(id)
|
||||||
FROM commits
|
FROM commits
|
||||||
WHERE repo_id = ?
|
WHERE repo_id = ?
|
||||||
AND branch = ?
|
AND branch = ?
|
||||||
GROUP BY branch)
|
GROUP BY branch)
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
`
|
`
|
||||||
|
|
||||||
|
// SQL Queries to fail all commits that are currently building
|
||||||
|
const commitFailUnfinishedStmt = `
|
||||||
|
UPDATE commits
|
||||||
|
SET status = 'Failure'
|
||||||
|
WHERE status IN ('Started', 'Pending')
|
||||||
|
`
|
||||||
|
|
||||||
// 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 FailUnfinishedCommits() error {
|
||||||
|
_, err := db.Exec(commitFailUnfinishedStmt)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue