# HG changeset patch # User Sascha L. Teichmann # Date 1554107774 -7200 # Node ID bfea3f80ca9a99d863badd163c02cfedef9e8488 # Parent 2cdf43c84a8cd201b818fc127e27d8fa14120bc9 Import queue: Extend the idea of changeset 2886:b150e5b37afe to some error cases that might happen before the storing of the after import state. diff -r 2cdf43c84a8c -r bfea3f80ca9a pkg/imports/queue.go --- a/pkg/imports/queue.go Fri Mar 29 14:23:06 2019 +0100 +++ b/pkg/imports/queue.go Mon Apr 01 10:36:14 2019 +0200 @@ -488,6 +488,30 @@ return &ji, nil } +func tryHardToStoreState(ctx context.Context, fn func(*sql.Conn) error) error { + // As it is important to keep the persistent model + // in sync with the in-memory model try harder to store + // the state. + const maxTries = 10 + var sleep = time.Second + + for try := 1; ; try++ { + var err error + if err = auth.RunAs(ctx, queueUser, fn); err == nil || try == maxTries { + return err + } + log.Printf("warn: [try %d/%d] Storing state failed: %v (try again in %s).\n", + try, maxTries, err, sleep) + + time.Sleep(sleep) + if sleep < time.Minute { + if sleep *= 2; sleep > time.Minute { + sleep = time.Minute + } + } + } +} + func updateStateSummary( ctx context.Context, id int64, @@ -503,37 +527,15 @@ s = sql.NullString{String: b.String(), Valid: true} } - // As it is important to keep the persistent model - // in sync with the in-memory model try harder to store - // the state. - const maxTries = 10 - var sleep = time.Second - - store := func(conn *sql.Conn) error { + return tryHardToStoreState(ctx, func(conn *sql.Conn) error { _, err := conn.ExecContext(ctx, updateStateSummarySQL, state, s, id) return err - } - - for try := 1; ; try++ { - var err error - if err = auth.RunAs(ctx, queueUser, store); err == nil || try == maxTries { - return err - } - log.Printf("warn: [try %d/%d] Storing state failed: %v (try again in %s).\n", - try, maxTries, err, sleep) - - time.Sleep(sleep) - if sleep < time.Minute { - if sleep *= 2; sleep > time.Minute { - sleep = time.Minute - } - } - } + }) } func errorAndFail(id int64, format string, args ...interface{}) error { ctx := context.Background() - err := auth.RunAs(ctx, queueUser, func(conn *sql.Conn) error { + return tryHardToStoreState(ctx, func(conn *sql.Conn) error { tx, err := conn.BeginTx(ctx, nil) if err != nil { return err @@ -551,7 +553,6 @@ } return err }) - return err } func (q *importQueue) importLoop() {