Skip to content

Commit

Permalink
[TM-1513] add attemps for delayed jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
egrojMonroy committed Nov 26, 2024
1 parent c624244 commit d5439fe
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/generated/apiFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ type JobResult = {
};
};

async function loadJob(signal: AbortSignal | undefined, delayedJobId: string): Promise<JobResult> {
async function loadJob(signal: AbortSignal | undefined, delayedJobId: string, retries: number = 3): Promise<JobResult> {
let response, error;
try {
const headers: HeadersInit = { "Content-Type": "application/json" };
Expand All @@ -145,6 +145,12 @@ async function loadJob(signal: AbortSignal | undefined, delayedJobId: string): P

const url = resolveV3Url(`/jobs/v3/delayedJobs/${delayedJobId}`);
response = await fetch(url, { signal, headers });

if (response.status === 502 && retries > 0) {
await new Promise(resolve => setTimeout(resolve, JOB_POLL_TIMEOUT));
return loadJob(signal, delayedJobId, retries - 1); // Retry
}

if (!response.ok) {
try {
error = {
Expand Down

0 comments on commit d5439fe

Please sign in to comment.