Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions apps/bullmq/src/jobs/pr-review-notification-retry.db.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions apps/bullmq/src/jobs/pr-review-notification.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions apps/bullmq/src/jobs/pr-review-notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ export const prReviewNotificationJob = async (

const deliveryStartedAt = Date.now();
const telemetry = createPrReviewNotificationTelemetry(events.length);
let preparationCompleted = false;

try {
const delivery = await preparePrReviewNotificationDelivery({
Expand All @@ -536,6 +537,7 @@ export const prReviewNotificationJob = async (
events,
telemetry,
});
preparationCompleted = true;

logPrReviewNotificationTriage({
data,
Expand Down Expand Up @@ -1171,11 +1173,22 @@ ${delivery.text}`;
telemetry,
});

// Put the drained events back so a retried job can deliver them.
// BullMQ retries carry the same token. Releasing it here makes that retry
// look superseded and forces preparation to wait for the scheduled drain.
if (
!preparationCompleted &&
data.ownershipVersion === 'canonical' &&
data.deliveryState === 'claimed' &&
job.attemptsMade + 1 < Math.max(job.opts.attempts ?? 1, 1)
) {
throw error;
}

// Exhausted retries and failures after preparation need a fresh durable claim.
try {
await requeuePendingPrReviewActivity({ target, events });
} catch {
// Best effort; the events are lost if Redis is unavailable too.
// Best effort; lease expiry remains the recovery backstop.
}

throw error;
Expand Down
1 change: 1 addition & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"globalPassThroughEnv": [
"APP_ENV",
"DATABASE_URL",
"REDIS_URL",
"MISE_DATA_DIR",
"MISE_CACHE_DIR",
"SKIP_ENV_VALIDATION",
Expand Down
Loading