fix(server/fileuploads): garbage collector should collect queued jobs which have reached max attempts (#5401)

This commit is contained in:
Iain Sproat
2025-09-09 15:06:08 +01:00
committed by GitHub
parent 8b822c91d1
commit 24d159d3cb
3 changed files with 33 additions and 16 deletions
@@ -65,20 +65,37 @@ export const failBackgroundJobsWhichExceedMaximumAttemptsOrNoRemainingComputeBud
.backgroundJobs(db)
.where(BackgroundJobs.withoutTablePrefix.col.originServerUrl, originServerUrl)
.andWhere(BackgroundJobs.withoutTablePrefix.col.jobType, jobType)
.whereIn(BackgroundJobs.withoutTablePrefix.col.status, [
BackgroundJobStatus.Queued,
BackgroundJobStatus.Processing
])
.andWhere(function () {
this.where(
BackgroundJobs.withoutTablePrefix.col.attempt,
'>', // greater than because processing jobs may currently equal maxAttempt and still be running
db.raw('"maxAttempt"') // camelCase requires the column name to be wrapped in double quotes
).orWhere(
BackgroundJobs.withoutTablePrefix.col.remainingComputeBudgetSeconds,
'<=',
0
)
this.where(function () {
this.where(
BackgroundJobs.withoutTablePrefix.col.status,
BackgroundJobStatus.Processing
).andWhere(
BackgroundJobs.withoutTablePrefix.col.attempt,
'>', // greater than because processing jobs may currently equal maxAttempt and still be running
db.raw('"maxAttempt"') // camelCase requires the column name to be wrapped in double quotes
)
})
.orWhere(function () {
this.where(
BackgroundJobs.withoutTablePrefix.col.status,
BackgroundJobStatus.Queued
).andWhere(
BackgroundJobs.withoutTablePrefix.col.attempt,
'>=', // greater or equal than because queued jobs cannot be picked up by a worker when they reach maxAttempt
db.raw('"maxAttempt"') // camelCase requires the column name to be wrapped in double quotes
)
})
.orWhere(function () {
this.whereIn(BackgroundJobs.withoutTablePrefix.col.status, [
BackgroundJobStatus.Queued,
BackgroundJobStatus.Processing
]).where(
BackgroundJobs.withoutTablePrefix.col.remainingComputeBudgetSeconds,
'<=',
0
)
})
})
.update({
[BackgroundJobs.withoutTablePrefix.col.status]: BackgroundJobStatus.Failed
@@ -174,10 +174,10 @@ describe('Background Jobs repositories @backgroundjobs', () => {
})
describe('failQueuedBackgroundJobsWhichExceedMaximumAttemptsOrNoRemainingComputeBudgetFactory', () => {
it('should fail queued background jobs that exceed maximum attempts', async () => {
it('should fail queued background jobs that meet or exceed maximum attempts', async () => {
const job = createTestJob({
status: BackgroundJobStatus.Queued,
attempt: 3,
attempt: 2,
maxAttempt: 2
})
await storeBackgroundJob({ job })
@@ -179,7 +179,7 @@ describe('File import garbage collection @fileuploads integration', () => {
testData: identifiableData,
blobId: fileTwo.fileId
}),
attempt: 4,
attempt: 3,
maxAttempt: 3
})
await saveUploadFile(fileOne)