# HG changeset patch # User Sascha L. Teichmann # Date 1586856973 -7200 # Node ID 4f0869b8503805e87fade6de6465b3499dd74f5a # Parent a74390e92c3c9b15ed668d2b58807323494fab6b Import queue: Limit number of repetions of failed jobs to 200 and wait at least 5 seconds between the attempts. diff -r a74390e92c3c -r 4f0869b85038 pkg/imports/queue.go --- a/pkg/imports/queue.go Tue Apr 07 16:34:35 2020 +0200 +++ b/pkg/imports/queue.go Tue Apr 14 11:36:13 2020 +0200 @@ -125,6 +125,11 @@ reviewJobWait = time.Minute ) +const ( + hardMaxTries = 200 + minWaitRetry = 5 * time.Second +) + var ErrRetrying = errors.New("retrying") type importQueue struct { @@ -512,12 +517,25 @@ var tl sql.NullInt64 if triesLeft != nil { - tl = sql.NullInt64{Int64: int64(*triesLeft), Valid: true} + var many int64 + if *triesLeft > hardMaxTries || *triesLeft < 0 { + many = hardMaxTries + } else { + many = int64(*triesLeft) + } + tl = sql.NullInt64{Int64: many, Valid: true} } var wr pgtype.Interval if waitRetry != nil { - if err := wr.Set(*waitRetry); err != nil { + var howLong time.Duration + if minWaitRetry > *waitRetry { + howLong = minWaitRetry + } else { + howLong = *waitRetry + } + + if err := wr.Set(howLong); err != nil { return 0, nil, err } } else { @@ -810,9 +828,24 @@ } _, err = tx.ExecContext(ctx, updateStateSQL, "running", ji.id) if err == nil { - err = tx.Commit() + if err = tx.Commit(); err != nil { + return err + } } - return err + // Clip repetition back to allowd values. + if ji.waitRetry.Status == pgtype.Present { + var d time.Duration + ji.waitRetry.AssignTo(&d) + if d < minWaitRetry { + ji.waitRetry.Set(minWaitRetry) + } + } + if ji.triesLeft.Valid { + if ji.triesLeft.Int64 < 0 || ji.triesLeft.Int64 > hardMaxTries { + ji.triesLeft.Int64 = hardMaxTries + } + } + return nil }) switch { case err == sql.ErrNoRows: