fix: harden stale import job detection and cancellation cleanup

- Extend stale-job auto-cancel to cover `running` jobs (30 min threshold) in addition to `pending` jobs (5 min), so crashed mid-import workers don't permanently block new imports
- Use `startedAt` instead of `createdAt` when calculating age for running jobs
- Scope `readImportJob` in the SSE loop to the authenticated user's ID to prevent cross-user job reads
- Persist progress counters (`processedItems`, `importedCount`, `skippedCount`, `failedCount`) when a job is cancelled mid-run so the UI shows accurate final stats
This commit is contained in:
2026-03-22 10:17:17 -04:00
parent fd4a8119ce
commit 72f26f822c
2 changed files with 13 additions and 3 deletions
+4
View File
@@ -363,6 +363,10 @@ export async function processImportJob(jobId: string): Promise<void> {
if (currentStatus?.status === "cancelled") {
updateImportJobProgress(jobId, {
finishedAt: new Date(),
processedItems: i,
importedCount: result.imported,
skippedCount: result.skipped,
failedCount: result.failed,
errors: JSON.stringify(result.errors),
warnings: JSON.stringify(result.warnings),
currentMessage: "Import cancelled",