mirror of
https://github.com/Crosstalk-Solutions/project-nomad.git
synced 2026-04-05 00:06:17 +02:00
fix download retry config and abort handling
This commit is contained in:
parent
6fddfba000
commit
6401021364
|
|
@ -54,6 +54,11 @@ export class RunDownloadJob {
|
||||||
totalBytes: 0,
|
totalBytes: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Track whether cancellation was explicitly requested by the user (via Redis signal
|
||||||
|
// or in-process AbortController). BullMQ lock mismatches can also abort the download
|
||||||
|
// stream, but those should be retried — only user-initiated cancels are unrecoverable.
|
||||||
|
let userCancelled = false
|
||||||
|
|
||||||
// Poll Redis for cancel signal every 2s — independent of progress events so cancellation
|
// Poll Redis for cancel signal every 2s — independent of progress events so cancellation
|
||||||
// works even when the stream is stalled and no onProgress ticks are firing.
|
// works even when the stream is stalled and no onProgress ticks are firing.
|
||||||
let cancelPollInterval: ReturnType<typeof setInterval> | null = setInterval(async () => {
|
let cancelPollInterval: ReturnType<typeof setInterval> | null = setInterval(async () => {
|
||||||
|
|
@ -61,6 +66,7 @@ export class RunDownloadJob {
|
||||||
const val = await cancelRedis.get(RunDownloadJob.cancelKey(job.id!))
|
const val = await cancelRedis.get(RunDownloadJob.cancelKey(job.id!))
|
||||||
if (val) {
|
if (val) {
|
||||||
await cancelRedis.del(RunDownloadJob.cancelKey(job.id!))
|
await cancelRedis.del(RunDownloadJob.cancelKey(job.id!))
|
||||||
|
userCancelled = true
|
||||||
abortController.abort()
|
abortController.abort()
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|
@ -176,8 +182,9 @@ export class RunDownloadJob {
|
||||||
filepath,
|
filepath,
|
||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
// If this was a cancellation abort, don't let BullMQ retry
|
// Only prevent retries for user-initiated cancellations. BullMQ lock mismatches
|
||||||
if (error?.message?.includes('aborted') || error?.message?.includes('cancelled')) {
|
// can also abort the stream, and those should be retried with backoff.
|
||||||
|
if (userCancelled) {
|
||||||
throw new UnrecoverableError(`Download cancelled: ${error.message}`)
|
throw new UnrecoverableError(`Download cancelled: ${error.message}`)
|
||||||
}
|
}
|
||||||
throw error
|
throw error
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user