# HG changeset patch # User Sascha L. Teichmann # Date 1540224856 -7200 # Node ID fcf016ebdef4feacfa4e1fa61b54f20374762c77 # Parent 7a4d233be077cdc75ee04b481fe912fd64ad9f57 Re-enqueue import jobs in state running if the the gemma server starts. These are jobs that where started but did not finish before the server died before. diff -r 7a4d233be077 -r fcf016ebdef4 pkg/imports/queue.go --- a/pkg/imports/queue.go Mon Oct 22 17:39:25 2018 +0200 +++ b/pkg/imports/queue.go Mon Oct 22 18:14:16 2018 +0200 @@ -49,6 +49,11 @@ const ( queueUser = "sys_admin" + reEnqueueRunningSQL = ` +UPDATE waterway.imports SET state = 'queued'::waterway.import_state +WHERE state = 'running'::waterway.import_state +` + insertJobSQL = ` INSERT INTO waterway.imports ( kind, @@ -164,6 +169,14 @@ } } +func reEnqueueRunning() error { + ctx := context.Background() + return auth.RunAs(queueUser, ctx, func(conn *sql.Conn) error { + _, err := conn.ExecContext(ctx, reEnqueueRunningSQL) + return err + }) +} + func fetchJob() (*idJob, error) { var ji idJob ctx := context.Background() @@ -225,6 +238,12 @@ func importLoop() { config.WaitReady() + // re-enqueue the jobs that are in state running. + // They where in progess when the server went down. + if err := reEnqueueRunning(); err != nil { + log.Printf("re-enquing failed: %v", err) + } + for { var idj *idJob var err error