Skip to content

Commit

Permalink
feat(retry render and dnb): retry puppetteer on failure and render ro…
Browse files Browse the repository at this point in the history
…utes on full render only (#256)
  • Loading branch information
SanderElias authored Jan 30, 2020
1 parent e54dac4 commit 471c2eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 12 additions & 0 deletions scully/renderPlugins/puppeteerRenderPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {scullyConfig} from '../utils/config';
import {logError, yellow} from '../utils/log';
import {launchedBrowser} from './launchedBrowser';

const errorredPages = new Set<string>();

export const puppeteerRender = async (route: HandledRoute): Promise<string> => {
let version = '0.0.0';
try {
Expand Down Expand Up @@ -70,6 +72,16 @@ export const puppeteerRender = async (route: HandledRoute): Promise<string> => {
// tslint:disable-next-line: no-unused-expression
page && typeof page.close === 'function' && (await page.close());
logError(`Puppeteer error while rendering "${yellow(route.route)}"`, err);
if (errorredPages.has(route.route)) {
/** we tried this page before, something is really off. Exit stage left. */
process.exit(15);
} else {
errorredPages.add(route.route);
/** give it a couple of secs */
await waitForIt(3 * 1000);
/** retry! */
return puppeteerRender(route);
}
}

return pageHtml;
Expand Down
9 changes: 6 additions & 3 deletions scully/utils/defaultAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const {baseFilter} = yargs
.describe('bf', 'provide a minimatch glob for the unhandled routes').argv;

console.log(baseFilter);
export const generateAll = async (config?: Partial<ScullyConfig>) => {
export const generateAll = async (config?: Partial<ScullyConfig>, localBaseFilter = baseFilter) => {
if (config) {
await updateScullyConfig(config);
}
Expand All @@ -36,10 +36,13 @@ export const generateAll = async (config?: Partial<ScullyConfig>) => {

log('Pull in data to create additional routes.');
const handledRoutes = await addOptionalRoutes(
unhandledRoutes.filter((r: string) => r && r.startsWith(baseFilter))
unhandledRoutes.filter((r: string) => r && r.startsWith(localBaseFilter))
);
/** save routerinfo, so its available during rendering */
await storeRoutes(handledRoutes);
if (localBaseFilter === '') {
/** only store when the routes are complete */
await storeRoutes(handledRoutes);
}

/** launch the browser, its shared among renderers */
const browser = await launchedBrowser();
Expand Down

0 comments on commit 471c2eb

Please sign in to comment.