Mercurial > gemma
diff pkg/imports/queue.go @ 1975:d966f03ea819
Imports: Added the new state 'unchanged' which can be issued by the imports to indicate that the database is not modified by the particular imports.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 23 Jan 2019 11:20:14 +0100 |
parents | 40cbfd268aa9 |
children | 8eeb0b5eb340 |
line wrap: on
line diff
--- a/pkg/imports/queue.go Wed Jan 23 11:07:17 2019 +0100 +++ b/pkg/imports/queue.go Wed Jan 23 11:20:14 2019 +0100 @@ -51,6 +51,10 @@ When time.Time } + // UnchangedError may be issued by Do of a Job to indicate + // That the database has not changed. + UnchangedError string + // Job is the central abstraction of an import job // run by the import queue. Job interface { @@ -127,6 +131,7 @@ "queued", "running", "failed", + "unchanged", "pending", "accepted", "declined", @@ -206,6 +211,11 @@ return re.Message } +// Error makes UnchangedError an error. +func (ue UnchangedError) Error() string { + return string(ue) +} + func (q *importQueue) registerJobCreator(kind JobKind, jc JobCreator) { q.creatorsMu.Lock() defer q.creatorsMu.Unlock() @@ -544,28 +554,42 @@ return err }) })() - if errDo != nil { - feedback.Error("error do: %v", errDo) - } - // Should we try again? - retry, shouldRetry := errDo.(*RetryError) + + var retry *RetryError + var unchanged bool - if shouldRetry && idj.trysLeft.Valid { // NULL -> limit less - if idj.trysLeft.Int64--; idj.trysLeft.Int64 <= 0 { - shouldRetry = false + switch v := errDo.(type) { + case *RetryError: + // NULL -> limit less + if idj.trysLeft.Valid && idj.trysLeft.Int64 <= 1 { + feedback.Warn("import should be retried, but no retrys left") + } else { + if idj.trysLeft.Valid { + idj.trysLeft.Int64-- + } + feedback.Info("import failed but will be retried") + retry = v + } + case UnchangedError: + feedback.Info("unchanged: %s", v.Error()) + unchanged = true + default: + if errDo != nil { + feedback.Error("error in import: %v", errDo) } } var errCleanup error - if !shouldRetry { // cleanup debris - errCleanup = survive(job.CleanUp)() - if errCleanup != nil { + if retry == nil { // cleanup debris + if errCleanup = survive(job.CleanUp)(); errCleanup != nil { feedback.Error("error cleanup: %v", errCleanup) } } var state string switch { + case unchanged: + state = "unchanged" case errDo != nil || errCleanup != nil: state = "failed" case jc.AutoAccept(): @@ -581,7 +605,7 @@ go sendNotificationMail(idj.user, jc.Description(), state, idj.id) } - if shouldRetry { + if retry != nil { nid, err := q.addJob( idj.kind, retry.When, idj.trys(),