diff --git a/ts/jobs/AttachmentDownloadManager.ts b/ts/jobs/AttachmentDownloadManager.ts index 6da1862906e..941c5abe136 100644 --- a/ts/jobs/AttachmentDownloadManager.ts +++ b/ts/jobs/AttachmentDownloadManager.ts @@ -96,8 +96,14 @@ const DEFAULT_RETRY_CONFIG = { }, }; const BACKUP_RETRY_CONFIG = { - ...DEFAULT_RETRY_CONFIG, + // Always retry if we think the item may end up being backed up maxAttempts: Infinity, + backoffConfig: { + // 30 seconds, 5 minutes, 50 minutes, 500 minutes (~8.3hrs), (max) 3 days + multiplier: 10, + firstBackoffs: [30 * durations.SECOND], + maxBackoffTime: 3 * durations.DAY, + }, }; type RunDownloadAttachmentJobOptions = { @@ -224,7 +230,10 @@ export class AttachmentDownloadManager extends JobManager void; saveAttachmentDownloadJobs: (jobs: Array) => void; resetAttachmentDownloadActive: () => void; + resetBackupAttachmentDownloadJobsRetryAfter: () => void; removeAttachmentDownloadJob: (job: AttachmentDownloadJobType) => void; removeAttachmentDownloadJobsForMessage: (messageId: string) => void; removeAllBackupAttachmentDownloadJobs: () => void; diff --git a/ts/sql/Server.ts b/ts/sql/Server.ts index a8b29b9c032..b763c262cd5 100644 --- a/ts/sql/Server.ts +++ b/ts/sql/Server.ts @@ -599,6 +599,7 @@ export const DataWriter: ServerWritableInterface = { saveAttachmentDownloadJob, saveAttachmentDownloadJobs, resetAttachmentDownloadActive, + resetBackupAttachmentDownloadJobsRetryAfter, removeAttachmentDownloadJob, removeAttachmentDownloadJobsForMessage, removeAllBackupAttachmentDownloadJobs, @@ -5746,6 +5747,16 @@ function resetAttachmentDownloadActive(db: WritableDB): void { ).run(); } +function resetBackupAttachmentDownloadJobsRetryAfter(db: WritableDB): void { + db.prepare( + ` + UPDATE attachment_downloads + SET retryAfter = NULL + WHERE originalSource = 'backup_import' + ` + ).run(); +} + function removeAttachmentDownloadJob( db: WritableDB, job: Pick< diff --git a/ts/test-electron/services/AttachmentDownloadManager_test.ts b/ts/test-electron/services/AttachmentDownloadManager_test.ts index cf94aefc800..2ff7bd5ec66 100644 --- a/ts/test-electron/services/AttachmentDownloadManager_test.ts +++ b/ts/test-electron/services/AttachmentDownloadManager_test.ts @@ -502,6 +502,31 @@ describe('AttachmentDownloadManager/JobManager', () => { jobs[2], ]); }); + + it('retries backup job immediately if retryAfters are reset', async () => { + strictAssert(downloadManager, 'must exist'); + const jobs = await addJobs(1, { + source: AttachmentDownloadSource.BACKUP_IMPORT, + }); + const jobAttempts = getPromisesForAttempts(jobs[0], 2); + + runJob.callsFake(async () => { + return new Promise<{ status: 'finished' | 'retry' }>(resolve => { + Promise.resolve().then(() => { + resolve({ status: 'retry' }); + }); + }); + }); + + await downloadManager?.start(); + await jobAttempts[0].completed; + assertRunJobCalledWith([jobs[0]]); + + await DataWriter.resetBackupAttachmentDownloadJobsRetryAfter(); + await downloadManager.start(); + + await jobAttempts[1].completed; + }); describe('will drop jobs from non-media backup imports that are old', () => { it('will not queue attachments older than 90 days (2 * message queue time)', async () => { hasMediaBackups.returns(false); diff --git a/ts/util/backupMediaDownload.ts b/ts/util/backupMediaDownload.ts index ddccf3a8210..2c59ed5eb1f 100644 --- a/ts/util/backupMediaDownload.ts +++ b/ts/util/backupMediaDownload.ts @@ -20,6 +20,8 @@ export async function pauseBackupMediaDownload(): Promise { export async function resumeBackupMediaDownload(): Promise { log.info('Resuming media download'); + // Reset the retry-afters so that all jobs will be immediately retried + await DataWriter.resetBackupAttachmentDownloadJobsRetryAfter(); return startBackupMediaDownload(); }