Skip to content

Commit 4832886

Browse files
author
Ives van Hoorne
committed
More robust dependency fetching and module saving
1 parent 0b773fa commit 4832886

File tree

4 files changed

+65
-34
lines changed

4 files changed

+65
-34
lines changed

src/app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
})(window, document, 'script', 'dataLayer', 'GTM-T3L6RFK');
3636
</script>
3737
<!-- End Google Tag Manager -->
38-
<script src="https://cdn.ravenjs.com/3.14.0/raven.min.js" crossorigin="anonymous"></script>
38+
<script src="https://cdn.ravenjs.com/3.17.0/raven.min.js" crossorigin="anonymous"></script>
3939
<script async src="//cdn.headwayapp.co/widget.js"></script>
4040

4141
<script src="https://js.stripe.com/v3/"></script>

src/app/store/entities/sandboxes/actions/files.js

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -390,18 +390,26 @@ const saveModuleCode = (id: string, moduleId: string) => async (
390390
: module;
391391
dispatch(moduleActions.setCode(newModule.id, module.code));
392392

393-
await dispatch(
394-
doRequest(
395-
SAVE_MODULE_CODE_API_ACTIONS,
396-
`sandboxes/${sandboxId}/modules/${module.shortid}`,
397-
{
398-
method: 'PUT',
399-
body: { module: { code: module.code } },
400-
},
401-
),
402-
);
403-
404-
dispatch(moduleActions.setModuleSynced(newModule.id));
393+
try {
394+
await dispatch(
395+
doRequest(
396+
SAVE_MODULE_CODE_API_ACTIONS,
397+
`sandboxes/${sandboxId}/modules/${module.shortid}`,
398+
{
399+
method: 'PUT',
400+
body: { module: { code: module.code } },
401+
},
402+
),
403+
);
404+
dispatch(moduleActions.setModuleSynced(newModule.id));
405+
} catch (e) {
406+
dispatch(
407+
notificationActions.addNotification(
408+
'Could not save the module, please try again.',
409+
'error',
410+
),
411+
);
412+
}
405413
};
406414
/**
407415
* Updates all modules in a sandbox at once (only the code)
@@ -418,22 +426,31 @@ const massUpdateModules = (id: string) => async (
418426
const modulesInSandbox = sandbox.modules.map(mid => modules[mid]);
419427
const modulesNotInSyncInSandbox = modulesInSandbox.filter(m => m.isNotSynced);
420428

421-
await dispatch(
422-
doRequest(
423-
MASS_UPDATE_MODULE_API_ACTIONS,
424-
`sandboxes/${sandboxId}/modules/mupdate`,
425-
{
426-
method: 'PUT',
427-
body: {
428-
modules: modulesNotInSyncInSandbox,
429+
try {
430+
await dispatch(
431+
doRequest(
432+
MASS_UPDATE_MODULE_API_ACTIONS,
433+
`sandboxes/${sandboxId}/modules/mupdate`,
434+
{
435+
method: 'PUT',
436+
body: {
437+
modules: modulesNotInSyncInSandbox,
438+
},
429439
},
430-
},
431-
),
432-
);
440+
),
441+
);
433442

434-
modulesNotInSyncInSandbox.forEach(m =>
435-
dispatch(moduleActions.setModuleSynced(m.id)),
436-
);
443+
modulesNotInSyncInSandbox.forEach(m =>
444+
dispatch(moduleActions.setModuleSynced(m.id)),
445+
);
446+
} catch (e) {
447+
dispatch(
448+
notificationActions.addNotification(
449+
'Could not save the modules, please try again.',
450+
'error',
451+
),
452+
);
453+
}
437454
};
438455

439456
export default {

src/app/store/entities/sandboxes/actions/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ export default {
351351
} catch (e) {
352352
dispatch(
353353
notificationActions.addNotification(
354-
'Could not fetch dependencies',
354+
`Could not fetch dependencies: ${e.message}`,
355355
'error',
356356
),
357357
);

src/app/store/entities/sandboxes/bundler/index.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
// @flow
22
import _debug from 'app/utils/debug';
3+
import notifActions from 'app/store/notifications/actions';
34

45
import { createAPIActions } from '../../../api/actions'; // eslint-disable-line
56

67
import callApi from '../../../services/api';
78
import dependenciesToQuery from './dependencies-to-query';
89
import logError from '../../../../utils/error';
10+
import delay from '../../../services/delay';
911

1012
const debug = _debug('cs:app:packager');
1113

1214
export const PACKAGER_URL = 'https://webpack-dll-prod.herokuapp.com/v6';
1315

14-
const RETRY_COUNT = 10;
16+
const RETRY_COUNT = 20;
1517

1618
/**
1719
* Request the packager, if retries > RETRY_COUNT it will throw if something goes wrong
1820
* otherwise it will retry again with an incremented retry
1921
*
2022
* @param {string} query The dependencies to call
2123
*/
22-
async function requestPackager(query: string) {
24+
async function requestPackager(query: string, dispatch: ?Function) {
2325
let retries = 0;
2426

2527
while (true) {
2628
debug(`Trying to call packager for ${retries} time`);
2729
try {
2830
const url = `${PACKAGER_URL}/${query}`;
29-
const result = await callApi(`${url}/manifest.json`); // eslint-disable-line
31+
const result = await callApi(`${url}/manifest.json`); // eslint-disable-line no-await-in-loop
3032

3133
return { ...result, url };
3234
} catch (e) {
@@ -35,17 +37,28 @@ async function requestPackager(query: string) {
3537
// 504 status code means the bundler is still bundling
3638
if (retries < RETRY_COUNT && statusCode === 504) {
3739
retries += 1;
40+
} else if (retries < RETRY_COUNT && statusCode === 500) {
41+
if (dispatch) {
42+
dispatch(
43+
notifActions.addNotification(
44+
'It seems like all packagers are busy, retrying in 10 seconds...',
45+
'warning',
46+
),
47+
);
48+
}
49+
await delay(1000 * 10); // eslint-disable-line no-await-in-loop
50+
retries += 1;
3851
} else {
3952
throw e;
4053
}
4154
}
4255
}
4356
}
4457

45-
async function callPackager(dependencies: Object) {
58+
async function callPackager(dependencies: Object, dispatch: Function) {
4659
const dependencyUrl = dependenciesToQuery(dependencies);
4760

48-
const result = await requestPackager(dependencyUrl);
61+
const result = await requestPackager(dependencyUrl, dispatch);
4962
return result;
5063
}
5164

@@ -63,11 +76,12 @@ export default function fetch(
6376
dispatch({ type: actions.REQUEST, initial: true, id });
6477
// New Packager flow
6578
try {
66-
const result = await callPackager(npmDependencies);
79+
const result = await callPackager(npmDependencies, dispatch);
6780

6881
dispatch({ type: actions.SUCCESS, id, result });
6982
return result;
7083
} catch (e) {
84+
e.message = `Could not fetch dependencies: ${e.message}`;
7185
logError(e, { level: 'error', service: 'packager' });
7286
dispatch({ type: actions.FAILURE, id });
7387

0 commit comments

Comments
 (0)