From 42da5640ea6645b4e74d9454afa7d5a8a62b0639 Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Wed, 1 Nov 2023 16:09:40 +1030 Subject: [PATCH] DO-1560: make the re-caching concurrency configurable --- packages/prerender-fargate/index.ts | 2 ++ .../lib/prerender-fargate-options.ts | 16 ++++++++++++++++ .../prerender-fargate/lib/prerender-fargate.ts | 3 +++ .../recaching/prerender-recache-api-construct.ts | 6 +++++- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/prerender-fargate/index.ts b/packages/prerender-fargate/index.ts index ed7b803c..244c3380 100644 --- a/packages/prerender-fargate/index.ts +++ b/packages/prerender-fargate/index.ts @@ -1,6 +1,7 @@ import { PrerenderFargate } from "./lib/prerender-fargate"; import { PrerenderFargateOptions, + PrerenderFargateReachingOptions, PrerenderFargateScalingOptions, } from "./lib/prerender-fargate-options"; import { PrerenderTokenUrlAssociationOptions } from "./lib/recaching/prerender-tokens"; @@ -9,5 +10,6 @@ export { PrerenderFargate, PrerenderFargateOptions, PrerenderFargateScalingOptions, + PrerenderFargateReachingOptions, PrerenderTokenUrlAssociationOptions, }; diff --git a/packages/prerender-fargate/lib/prerender-fargate-options.ts b/packages/prerender-fargate/lib/prerender-fargate-options.ts index 95d1d22b..ca4c4865 100644 --- a/packages/prerender-fargate/lib/prerender-fargate-options.ts +++ b/packages/prerender-fargate/lib/prerender-fargate-options.ts @@ -89,6 +89,11 @@ export interface PrerenderFargateOptions { * for most of the cases. */ prerenderFargateScalingOptions?: PrerenderFargateScalingOptions; + /** + * Prerender Fargate Re-caching options + * This allows to alter the re-caching behavior. The default configuration should be sufficient. + */ + prerenderFargateReachingOptions?: PrerenderFargateReachingOptions; } /** @@ -137,3 +142,14 @@ export interface PrerenderFargateScalingOptions { */ unhealthyThresholdCount?: number; } + +/** + * Prerender Fargate Re-caching options + */ +export interface PrerenderFargateReachingOptions { + /** + * The maximum number of concurrent executions of the Prerender Re-cache API. + * @default - 1 + */ + maxConcurrentExecutions: number; +} \ No newline at end of file diff --git a/packages/prerender-fargate/lib/prerender-fargate.ts b/packages/prerender-fargate/lib/prerender-fargate.ts index 2988fc51..7cfc9c8e 100644 --- a/packages/prerender-fargate/lib/prerender-fargate.ts +++ b/packages/prerender-fargate/lib/prerender-fargate.ts @@ -100,6 +100,7 @@ export class PrerenderFargate extends Construct { prerenderName, minInstanceCount, prerenderFargateScalingOptions, + prerenderFargateReachingOptions, } = props; // Create bucket for prerender storage @@ -252,6 +253,8 @@ export class PrerenderFargate extends Construct { new PrerenderRecacheApi(this, `${prerenderName}-recache-api`, { prerenderS3Bucket: this.bucket, tokenList: Object.keys(tokenUrlAssociation.tokenUrlAssociation), + maxConcurrentExecutions: + prerenderFargateReachingOptions?.maxConcurrentExecutions || 1, }); } } diff --git a/packages/prerender-fargate/lib/recaching/prerender-recache-api-construct.ts b/packages/prerender-fargate/lib/recaching/prerender-recache-api-construct.ts index f197d29c..5adcba87 100644 --- a/packages/prerender-fargate/lib/recaching/prerender-recache-api-construct.ts +++ b/packages/prerender-fargate/lib/recaching/prerender-recache-api-construct.ts @@ -18,6 +18,10 @@ export interface PrerenderRecacheApiOptions { * A list of tokens used to authenticate API requests. */ tokenList: string[]; + /** + * Maximum number of concurrent executions of the Prerender Recache API. + */ + maxConcurrentExecutions: number; } /** @@ -48,8 +52,8 @@ export class PrerenderRecacheApi extends Construct { new LambdaToSqsToLambda(this, "prerenderRequestQueue", { existingProducerLambdaObj: apiHandler, existingConsumerLambdaObj: new NodejsFunction(this, "consumer", { + reservedConcurrentExecutions: options.maxConcurrentExecutions, timeout: Duration.seconds(60), - reservedConcurrentExecutions: 1, }), deployDeadLetterQueue: false, queueProps: { visibilityTimeout: Duration.minutes(60) },