fix(library): a scan cut off by a restart no longer blocks saving library folders
A restart mid-scan left its scan_runs row unfinished, and saving library
folders refused ("A library scan is running") until a later scan reaped it,
up to 12 hours on. Startup now closes such rows with the reason before the
boot scan, as backups already do. Saving folders and the duplicate sweep
share one check that treats a run past StuckScanThreshold as dead.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,24 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const failUnfinishedScanRuns = `-- name: FailUnfinishedScanRuns :execrows
|
||||
UPDATE scan_runs
|
||||
SET finished_at = now(),
|
||||
error_message = 'The server stopped while the scan was running.'
|
||||
WHERE finished_at IS NULL
|
||||
`
|
||||
|
||||
// At startup no scan can be running yet, so a row still unfinished was cut
|
||||
// off when the server last stopped. Closing it keeps it from reading as a
|
||||
// scan in progress, which would block saving library folders.
|
||||
func (q *Queries) FailUnfinishedScanRuns(ctx context.Context) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, failUnfinishedScanRuns)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const finishScanRun = `-- name: FinishScanRun :exec
|
||||
UPDATE scan_runs
|
||||
SET finished_at = now(),
|
||||
|
||||
Reference in New Issue
Block a user