MCPcopy
hub / github.com/triggerdotdev/trigger.dev / retryFetch

Function retryFetch

packages/trigger-sdk/src/v3/retry.ts:176–362  ·  view source on GitHub ↗
(
  input: RequestInfo | URL,
  init?: RetryFetchRequestInit | undefined
)

Source from the content-addressed store, hash-verified

174const MAX_ATTEMPTS = 10;
175
176async function retryFetch(
177 input: RequestInfo | URL,
178 init?: RetryFetchRequestInit | undefined
179): Promise<Response> {
180 return tracer.startActiveSpan(
181 "retry.fetch()",
182 async (span) => {
183 let attempt = 1;
184
185 while (true) {
186 try {
187 const abortController = new AbortController();
188
189 const timeoutId = init?.timeoutInMs
190 ? setTimeout(
191 () => {
192 abortController.abort();
193 },
194 init?.timeoutInMs
195 )
196 : undefined;
197
198 init?.signal?.addEventListener("abort", () => {
199 abortController.abort();
200 });
201
202 const [response, span] = await doFetchRequest(
203 input,
204 { ...(init ?? {}), signal: abortController.signal },
205 attempt
206 );
207
208 if (timeoutId) {
209 clearTimeout(timeoutId);
210 }
211
212 if (response.ok) {
213 span.setAttributes(createFetchResponseAttributes(response));
214
215 span.end();
216
217 return response;
218 }
219
220 const nextRetry = await calculateRetryDelayForResponse(
221 resolveDefaults(init?.retry, "byStatus", defaultFetchRetryOptions.byStatus),
222 response,
223 attempt
224 );
225
226 if (!nextRetry) {
227 span.setAttributes(createFetchResponseAttributes(response));
228
229 span.end();
230
231 return response;
232 }
233

Callers

nothing calls this directly

Calls 10

calculateNextRetryDelayFunction · 0.90
doFetchRequestFunction · 0.85
resolveDefaultsFunction · 0.85
createFetchAttributesFunction · 0.85
startActiveSpanMethod · 0.80
waitForDurationMethod · 0.65
waitUntilMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…