mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
cancel all pending or started builds when the app starts
This commit is contained in:
parent
88ee774d8d
commit
1a143f8fb4
3 changed files with 23 additions and 1 deletions
|
@ -93,6 +93,9 @@ func main() {
|
||||||
perms := perm.NewManager(db)
|
perms := perm.NewManager(db)
|
||||||
commits := commit.NewManager(db)
|
commits := commit.NewManager(db)
|
||||||
|
|
||||||
|
// cancel all previously running builds
|
||||||
|
go commits.CancelAll()
|
||||||
|
|
||||||
// setup the session managers
|
// setup the session managers
|
||||||
sess := session.NewSession(users)
|
sess := session.NewSession(users)
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,10 @@ type CommitManager interface {
|
||||||
|
|
||||||
// Delete removes the commit from the datastore.
|
// Delete removes the commit from the datastore.
|
||||||
Delete(commit *Commit) error
|
Delete(commit *Commit) error
|
||||||
|
|
||||||
|
// CancelAll will update the status of all Started or Pending
|
||||||
|
// builds to a status of Killed (cancelled).
|
||||||
|
CancelAll() error
|
||||||
}
|
}
|
||||||
|
|
||||||
// commitManager manages a list of commits in a SQL database.
|
// commitManager manages a list of commits in a SQL database.
|
||||||
|
@ -140,7 +144,16 @@ UPDATE output SET output_raw = ? WHERE commit_id = ?;
|
||||||
|
|
||||||
// SQL statement to delete a Commit by ID.
|
// SQL statement to delete a Commit by ID.
|
||||||
const deleteStmt = `
|
const deleteStmt = `
|
||||||
DELETE FROM commits WHERE commit_id = ?
|
DELETE FROM commits WHERE commit_id = ?;
|
||||||
|
`
|
||||||
|
|
||||||
|
// SQL statement to cancel all running Commits.
|
||||||
|
const cancelStmt = `
|
||||||
|
UPDATE commits SET
|
||||||
|
commit_status = ?,
|
||||||
|
commit_started = ?,
|
||||||
|
commit_finished = ?
|
||||||
|
WHERE commit_status IN ('Started', 'Pending');
|
||||||
`
|
`
|
||||||
|
|
||||||
func (db *commitManager) Find(id int64) (*Commit, error) {
|
func (db *commitManager) Find(id int64) (*Commit, error) {
|
||||||
|
@ -215,3 +228,8 @@ func (db *commitManager) Delete(commit *Commit) error {
|
||||||
_, err := db.Exec(deleteStmt, commit.ID)
|
_, err := db.Exec(deleteStmt, commit.ID)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *commitManager) CancelAll() error {
|
||||||
|
_, err := db.Exec(cancelStmt, StatusKilled, time.Now().Unix(), time.Now().Unix())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ const (
|
||||||
StatusSuccess = "Success"
|
StatusSuccess = "Success"
|
||||||
StatusFailure = "Failure"
|
StatusFailure = "Failure"
|
||||||
StatusError = "Error"
|
StatusError = "Error"
|
||||||
|
StatusKilled = "Killed"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Commit struct {
|
type Commit struct {
|
||||||
|
|
Loading…
Reference in a new issue