Permalink
Browse files

packager: GlobalTransformCache: throat() the file fetching function

Reviewed By: cpojer

Differential Revision: D4914187

fbshipit-source-id: ae3b8aa4ed4dbd1896ca35cf498b7c02fd109f58
  • Loading branch information...
jeanlauliac authored and facebook-github-bot committed Apr 19, 2017
1 parent aef2867 commit f519f16180c62066d27c2b1a0fdceacceb0b2d9a
Showing with 11 additions and 1 deletion.
  1. +11 −1 packager/src/lib/GlobalTransformCache.js
@@ -18,6 +18,7 @@ const crypto = require('crypto');
const fetch = require('node-fetch');
const jsonStableStringify = require('json-stable-stringify');
const path = require('path');
const throat = require('throat');
import type {
Options as TransformWorkerOptions,
@@ -260,7 +261,7 @@ class URIBasedGlobalTransformCache {
* a second time if we expect them to be transient. We might even consider
* waiting a little time before retring if experience shows it's useful.
*/
static fetchResultFromURI(uri: string): Promise<CachedResult> {
static _fetchResultFromURIWithRetry(uri: string): Promise<CachedResult> {
return URIBasedGlobalTransformCache._fetchResultFromURI(uri).catch(error => {
if (!URIBasedGlobalTransformCache.shouldRetryAfterThatError(error)) {
throw error;
@@ -269,6 +270,12 @@ class URIBasedGlobalTransformCache {
});
}
/**
* The exposed version uses throat() to limit concurrency, as making too many parallel requests
* is more likely to trigger server-side throttling and cause timeouts.
*/
static fetchResultFromURI: (uri: string) => Promise<CachedResult>;
/**
* We want to retry timeouts as they're likely temporary. We retry 503
* (Service Unavailable) and 502 (Bad Gateway) because they may be caused by a
@@ -311,6 +318,9 @@ class URIBasedGlobalTransformCache {
}
URIBasedGlobalTransformCache.fetchResultFromURI =
throat(500, URIBasedGlobalTransformCache._fetchResultFromURIWithRetry);
class OptionsHasher {
_rootPath: string;
_cache: WeakMap<TransformWorkerOptions, string>;

0 comments on commit f519f16

Please sign in to comment.