fix: introduced scraper timeout (#2724)

- fixes #2716
This commit is contained in:
Wyatt Johnson
2019-11-22 18:16:41 +00:00
committed by GitHub
parent 09cf8c5490
commit 787f1c68e7
15 changed files with 159 additions and 40 deletions
@@ -113,7 +113,14 @@ export default (ctx: TenantContext) => ({
},
}).then(primeStoriesFromConnection(ctx)),
debugScrapeMetadata: new DataLoader(
createManyBatchLoadFn((url: string) => scraper.scrape(url)),
createManyBatchLoadFn((url: string) =>
// This typecast is needed because the custom `ms` format does not return
// the desired `number` type even though that's the only type it can
// output.
scraper.scrape(url, (ctx.config.get(
"scrape_timeout"
) as unknown) as number)
),
{
// Disable caching for the DataLoader if the Context is designed to be
// long lived.
@@ -31,6 +31,7 @@ export const Stories = (ctx: TenantContext) => ({
create(
ctx.mongo,
ctx.tenant,
ctx.config,
input.story.id,
input.story.url,
omitBy(input.story, isNull),
@@ -72,5 +73,5 @@ export const Stories = (ctx: TenantContext) => ({
remove: async (input: GQLRemoveStoryInput): Promise<Readonly<Story> | null> =>
remove(ctx.mongo, ctx.tenant, input.id, input.includeComments),
scrape: async (input: GQLScrapeStoryInput): Promise<Readonly<Story> | null> =>
scrape(ctx.mongo, ctx.tenant.id, input.id),
scrape(ctx.mongo, ctx.config, ctx.tenant.id, input.id),
});
@@ -263,12 +263,11 @@ export function createSubscriptionServer(
schema: GraphQLSchema,
options: Options
) {
const keepAlive = options.config.get("websocket_keep_alive_timeout");
if (typeof keepAlive !== "number" || keepAlive <= 0) {
throw new Error(
"expected the websocket_keep_alive_timeout configuration to be a positive number"
);
}
// This typecast is needed because the custom `ms` format does not return the
// desired `number` type even though that's the only type it can output.
const keepAlive = (options.config.get(
"websocket_keep_alive_timeout"
) as unknown) as number;
return SubscriptionServer.create(
{