fix(server/m7-recurring-scans): early-return in TryStartScan reap branch

revive flagged the if/else where the else branch was a return — invert
the condition and return the non-stale skip path early so the reap
flow drops one indent level.
This commit is contained in:
2026-05-06 23:03:21 -04:00
parent 837db5c929
commit 876f994904
+10 -11
View File
@@ -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)
}