diff --git a/store/datastore/store.go b/store/datastore/store.go index 2f427652..b6e4de48 100644 --- a/store/datastore/store.go +++ b/store/datastore/store.go @@ -83,6 +83,7 @@ func Open(driver, config string) *sql.DB { log.Errorln(err) log.Fatalln("migration failed") } + cleanupDatabase(db) return db } @@ -128,6 +129,13 @@ func setupDatabase(driver string, db *sql.DB) error { return err } +// helper function to avoid stuck jobs when Drone unexpectedly +// restarts. This is a temp fix for https://github.com/drone/drone/issues/1195 +func cleanupDatabase(db *sql.DB) { + db.Exec("update builds set build_status = 'error' where build_status IN ('pending','running')") + db.Exec("update jobs set job_status = 'error' where job_status IN ('pending','running')") +} + // helper function to setup the meddler default driver // based on the selected driver name. func setupMeddler(driver string) {