fix: close cleanup and replay races, integer thumbnail sizing, sharp deadline, contract tests
This commit is contained in:
+17
-6
@@ -187,7 +187,12 @@ export async function republishStale(
|
||||
return stale.length;
|
||||
}
|
||||
|
||||
export type ReplayResult = 'replayed' | 'already_ready' | 'not_failed' | 'not_found';
|
||||
export type ReplayResult =
|
||||
| 'replayed'
|
||||
| 'already_ready'
|
||||
| 'not_failed'
|
||||
| 'source_missing'
|
||||
| 'not_found';
|
||||
|
||||
export async function replayJob(
|
||||
prisma: PrismaClient,
|
||||
@@ -203,6 +208,16 @@ export async function replayJob(
|
||||
if (job.status === 'ready') {
|
||||
return 'already_ready';
|
||||
}
|
||||
if (job.status !== 'failed') {
|
||||
return 'not_failed';
|
||||
}
|
||||
const source = await tx.attachment.updateMany({
|
||||
where: { id: job.attachmentId, status: 'failed', stagingKey: { not: null } },
|
||||
data: { status: 'queued', errorCode: null },
|
||||
});
|
||||
if (source.count === 0) {
|
||||
return 'source_missing';
|
||||
}
|
||||
const taken = await tx.attachmentJob.updateMany({
|
||||
where: { id: jobId, status: 'failed' },
|
||||
data: {
|
||||
@@ -214,12 +229,8 @@ export async function replayJob(
|
||||
},
|
||||
});
|
||||
if (taken.count === 0) {
|
||||
return 'not_failed';
|
||||
throw new Error('job changed during replay');
|
||||
}
|
||||
await tx.attachment.update({
|
||||
where: { id: job.attachmentId },
|
||||
data: { status: 'queued', errorCode: null },
|
||||
});
|
||||
await tx.jobEvent.create({
|
||||
data: {
|
||||
jobId,
|
||||
|
||||
Reference in New Issue
Block a user