Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the re-caching concurrency configurable #1174

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/prerender-fargate/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PrerenderFargate } from "./lib/prerender-fargate";
import {
PrerenderFargateOptions,
PrerenderFargateRecachingOptions,
PrerenderFargateScalingOptions,
} from "./lib/prerender-fargate-options";
import { PrerenderTokenUrlAssociationOptions } from "./lib/recaching/prerender-tokens";
Expand All @@ -9,5 +10,6 @@ export {
PrerenderFargate,
PrerenderFargateOptions,
PrerenderFargateScalingOptions,
PrerenderFargateRecachingOptions,
PrerenderTokenUrlAssociationOptions,
};
17 changes: 16 additions & 1 deletion packages/prerender-fargate/lib/prerender-fargate-options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PrerenderTokenUrlAssociationOptions } from "./recaching/prerender-tokens";
import * as ec2 from "aws-cdk-lib/aws-ec2";

/**
* Options for configuring the Prerender Fargate construct.
Expand Down Expand Up @@ -89,6 +88,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.
*/
prerenderFargateRecachingOptions?: PrerenderFargateRecachingOptions;
}

/**
Expand Down Expand Up @@ -137,3 +141,14 @@ export interface PrerenderFargateScalingOptions {
*/
unhealthyThresholdCount?: number;
}

/**
* Prerender Fargate Re-caching options
*/
export interface PrerenderFargateRecachingOptions {
/**
* The maximum number of concurrent executions of the Prerender Re-cache API.
* @default - 1
*/
maxConcurrentExecutions: number;
}
3 changes: 3 additions & 0 deletions packages/prerender-fargate/lib/prerender-fargate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class PrerenderFargate extends Construct {
prerenderName,
minInstanceCount,
prerenderFargateScalingOptions,
prerenderFargateRecachingOptions,
} = props;

// Create bucket for prerender storage
Expand Down Expand Up @@ -252,6 +253,8 @@ export class PrerenderFargate extends Construct {
new PrerenderRecacheApi(this, `${prerenderName}-recache-api`, {
prerenderS3Bucket: this.bucket,
tokenList: Object.keys(tokenUrlAssociation.tokenUrlAssociation),
maxConcurrentExecutions:
prerenderFargateRecachingOptions?.maxConcurrentExecutions || 1,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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) },
Expand Down