Skip to content
Closed
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
16 changes: 15 additions & 1 deletion packages/das/src/webhook/handlers/pull-request.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ export class PullRequestHandler {
];
if (metadataActions.includes(action)) {
const jobId = `meta-${repoFullName}-${prNumber}`;
await this.removeRetainedFailedMetadataJob(jobId);
await this.fetchQueue.add(
FETCH_JOBS.PR_METADATA,
{ repoFullName, prNumber },
{
jobId,
// Replace any pending job for the same PR (e.g. rapid pushes)
// Deduplicate pending/active jobs for the same PR.
removeOnComplete: true,
removeOnFail: 50,
attempts: 3,
Expand Down Expand Up @@ -117,4 +118,17 @@ export class PullRequestHandler {
);
}
}

private async removeRetainedFailedMetadataJob(jobId: string): Promise<void> {
const existingJob = await this.fetchQueue.getJob(jobId);
if (!existingJob) return;

const state = await existingJob.getState();
if (state !== "failed") return;

await existingJob.remove();
this.logger.warn(
`Removed retained failed PR metadata job ${jobId} before requeueing`,
);
}
}