11import _debug from 'app/utils/debug' ;
22import dependenciesToQuery from './dependencies-to-query' ;
3- import { PACKAGER_URL } from './' ;
43import delay from '../utils/delay' ;
54import actions , { dispatch } from '../actions' ;
65import setScreen from '../status-screen' ;
@@ -9,7 +8,6 @@ type Dependencies = {
98 [ dependency : string ] : string ,
109} ;
1110
12- const RETRY_COUNT = 60 ;
1311const debug = _debug ( 'cs:sandbox:packager' ) ;
1412
1513function callApi ( url : string ) {
@@ -26,39 +24,44 @@ function callApi(url: string) {
2624 . then ( response => response . json ( ) ) ;
2725}
2826
27+ export const PACKAGER_URL = 'https://webpack-dll-prod.herokuapp.com/v6' ;
28+ export const NEW_PACKAGER_URL =
29+ 'https://42qpdtykai.execute-api.eu-west-1.amazonaws.com/prod/package' ;
30+
31+ const RETRY_COUNT = 20 ;
32+
2933/**
3034 * Request the packager, if retries > RETRY_COUNT it will throw if something goes wrong
3135 * otherwise it will retry again with an incremented retry
3236 *
3337 * @param {string } query The dependencies to call
3438 */
35- async function requestManifest ( url ) {
39+ async function requestPackager ( query : string ) {
3640 let retries = 0 ;
3741
3842 while ( true ) {
3943 debug ( `Trying to call packager for ${ retries } time` ) ;
4044 try {
41- const manifest = await callApi ( url ) ; // eslint-disable-line no-await-in-loop
45+ const url = `${ PACKAGER_URL } /${ query } ` ;
46+ const result = await callApi ( `${ url } /manifest.json` ) ; // eslint-disable-line no-await-in-loop
4247
43- return manifest ;
48+ return { ... result , url } ;
4449 } catch ( e ) {
4550 const statusCode = e . response && e . response . status ;
4651
47- setScreen ( { type : 'loading' , text : 'Bundling Dependencies...' } ) ;
48-
49- // 403 status code means the bundler is still bundling
50- if ( retries < RETRY_COUNT && statusCode === 403 ) {
52+ // 504 status code means the bundler is still bundling
53+ if ( retries < RETRY_COUNT && statusCode === 504 ) {
5154 retries += 1 ;
52- await delay ( 1000 * 2 ) ; // eslint-disable-line no-await-in-loop
5355 } else if ( retries < RETRY_COUNT && statusCode === 500 ) {
54- dispatch (
55- actions . notifications . showNotification (
56- 'It seems like all packagers are busy, retrying in 10 seconds...' ,
57- 'warning' ,
58- ) ,
59- ) ;
60-
61- await delay ( 1000 * 2 ) ; // eslint-disable-line no-await-in-loop
56+ if ( dispatch ) {
57+ dispatch (
58+ actions . notifications . showNotification (
59+ 'It seems like all packagers are busy, retrying in 10 seconds...' ,
60+ 'warning' ,
61+ ) ,
62+ ) ;
63+ }
64+ await delay ( 1000 * 10 ) ; // eslint-disable-line no-await-in-loop
6265 retries += 1 ;
6366 } else {
6467 throw e ;
@@ -70,19 +73,26 @@ async function requestManifest(url) {
7073async function callPackager ( dependencies : Object ) {
7174 const dependencyUrl = dependenciesToQuery ( dependencies ) ;
7275
73- const result = await callApi ( `${ PACKAGER_URL } /${ dependencyUrl } ` ) ;
74-
75- const dataUrl = result . url ;
76- const manifest = await requestManifest ( `${ dataUrl } /manifest.json` ) ;
76+ try {
77+ // Warmup cache
78+ window . fetch ( `${ NEW_PACKAGER_URL } /${ dependencyUrl } ` ) ;
79+ } catch ( e ) {
80+ console . error ( e ) ;
81+ }
7782
78- return { url : dataUrl , manifest } ;
83+ const manifest = await requestPackager ( dependencyUrl ) ;
84+ return manifest ;
7985}
8086
87+ // eslint-disable-next-line
88+ /*::
89+ const _apiActions = createAPIActions('pref', 'act');
90+ */
8191export default async function fetchDependencies ( npmDependencies : Dependencies ) {
8292 if ( Object . keys ( npmDependencies ) . length !== 0 ) {
8393 // New Packager flow
8494 try {
85- const result = await callPackager ( npmDependencies ) ;
95+ const result = await callPackager ( npmDependencies , dispatch ) ;
8696
8797 return result ;
8898 } catch ( e ) {
0 commit comments