diff --git a/backend/src/__tests__/upload.worker.test.ts b/backend/src/__tests__/upload.worker.test.ts index 9cc2d8e..a34659b 100644 --- a/backend/src/__tests__/upload.worker.test.ts +++ b/backend/src/__tests__/upload.worker.test.ts @@ -106,11 +106,11 @@ describe('upload worker — retryable errors escape the processor without a DB u // it calls updateUploadStatus('failed') so the row no longer stays permanently // stuck at 'in_progress'. -describe('upload worker — failed handler skips DB on intermediate BullMQ attempt', () => { +describe('upload worker — failed handler resets status to queued on intermediate BullMQ attempt', () => { it.each([ ['HashLockError', new HashLockError('lock already held')], ['SourceCdnError', new SourceCdnError('cdn network error (ECONNRESET)')], - ])('%s: does not touch the DB when BullMQ will retry', async (_name, error) => { + ])('%s: resets status to queued when BullMQ will retry', async (_name, error) => { const failedHandler = capturedHandlers.get('failed') expect(failedHandler).toBeDefined() @@ -119,9 +119,20 @@ describe('upload worker — failed handler skips DB on intermediate BullMQ attem await failedHandler!(job, error) - expect(mockUpdateStatus).not.toHaveBeenCalled() + expect(mockUpdateStatus).toHaveBeenCalledWith(1, 'queued') expect(mockClearToken).not.toHaveBeenCalled() }) + + it('swallows DB errors when resetting status to queued so the handler never rejects', async () => { + mockUpdateStatus.mockRejectedValueOnce(new Error('DB connection lost')) + + const failedHandler = capturedHandlers.get('failed') + expect(failedHandler).toBeDefined() + + const job = { ...makeJob(1), attemptsMade: 1, opts: { attempts: 3 } } + + await expect(failedHandler!(job, new SourceCdnError('cdn error'))).resolves.toBeUndefined() + }) }) describe('upload worker — permanent BullMQ failure marks upload as failed in DB', () => { diff --git a/backend/src/workers/upload.worker.ts b/backend/src/workers/upload.worker.ts index df863cd..3d74c70 100644 --- a/backend/src/workers/upload.worker.ts +++ b/backend/src/workers/upload.worker.ts @@ -253,12 +253,20 @@ export function createUploadWorker(redis: Redis, deps?: WorkerDeps): Worker