diff --git a/internal/library/trigger.go b/internal/library/trigger.go index 7bc9c45b..52c3e8bd 100644 --- a/internal/library/trigger.go +++ b/internal/library/trigger.go @@ -39,19 +39,18 @@ func TryStartScan(ctx context.Context, pool *pgxpool.Pool, if qerr == nil { // Found an in-flight row. Reap if stale, else skip. age := time.Since(row.StartedAt.Time) - if age > StuckScanThreshold { - logger.Warn("reaping stale in-flight scan", - "id", row.ID, "started_at", row.StartedAt.Time, "age", age) - if rerr := q.FinishScanRun(ctx, dbq.FinishScanRunParams{ - ID: row.ID, - Column2: "reaped (stale)", - }); rerr != nil { - return false, nil, fmt.Errorf("reap stale scan: %w", rerr) - } - // Fall through to start a new scan. - } else { + if age <= StuckScanThreshold { return false, &row, nil } + logger.Warn("reaping stale in-flight scan", + "id", row.ID, "started_at", row.StartedAt.Time, "age", age) + if rerr := q.FinishScanRun(ctx, dbq.FinishScanRunParams{ + ID: row.ID, + Column2: "reaped (stale)", + }); rerr != nil { + return false, nil, fmt.Errorf("reap stale scan: %w", rerr) + } + // Fall through to start a new scan. } else if !errors.Is(qerr, pgx.ErrNoRows) { return false, nil, fmt.Errorf("in-flight check: %w", qerr) }