MCPcopy
hub / github.com/meteor/meteor / attempt

Function attempt

tools/utils/http-helpers.js:455–496  ·  view source on GitHub ↗
(triesRemaining = maxAttempts, startAt = 0)

Source from the content-addressed store, hash-verified

453 const outputStream = new ConcatStream();
454
455 function attempt(triesRemaining = maxAttempts, startAt = 0) {
456 if (startAt > 0) {
457 options.headers = {
458 ...options.headers,
459 Range: `bytes=${startAt}-`
460 };
461 }
462
463 if (masterProgress &&
464 masterProgress.addChildTask) {
465 options.progress = masterProgress.addChildTask({
466 title: masterProgress.title
467 });
468 }
469
470 try {
471 return Promise.resolve(httpHelpers.request({
472 outputStream,
473 ...options,
474 }));
475
476 } catch (e) {
477 const size = outputStream.size;
478 const useTry = size === startAt;
479 const change = size - startAt;
480
481 if (!useTry || triesRemaining > 0) {
482 if (useTry) {
483 Console.debug(`Request failed, ${triesRemaining - 1} attempts left`);
484 } else {
485 Console.debug(`Request failed after ${change} bytes, retrying`);
486 }
487
488 return new Promise(
489 resolve => setTimeout(resolve, retryDelaySecs * 1000)
490 ).then(() => attempt(triesRemaining - (useTry ? 1 : 0), size));
491 }
492
493 Console.debug(`Request failed ${maxAttempts} times: failing`);
494 return Promise.reject(new files.OfflineError(e));
495 }
496 }
497
498 const result = attempt().await();
499 const response = result.response

Callers 1

getUrlWithResumingFunction · 0.70

Calls 3

addChildTaskMethod · 0.80
resolveMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…