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

Fix getlift/lift#208, allow for batchSize above 10 #317

Merged
merged 1 commit into from
Jun 16, 2023
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
3 changes: 2 additions & 1 deletion docs/queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ By default, Lift configures Lambda to be invoked with 1 messages at a time. The

Note you can use [partial batch failures](#partial-batch-failures) to avoid failing the whole batch.

It is possible to set the batch size between 1 and 10.
It is possible to set the batch size between 1 and 10 for FIFO queues and 10000 for regular queues.
For batch size over 10, [maxBatchingWindow](#maximum-batching-window) must be set.

### Max Concurrency

Expand Down
19 changes: 18 additions & 1 deletion src/constructs/aws/Queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const QUEUE_DEFINITION = {
batchSize: {
type: "number",
minimum: 1,
maximum: 10,
maximum: 10000,
},
maxBatchingWindow: {
type: "number",
Expand Down Expand Up @@ -167,6 +167,23 @@ export class Queue extends AwsConstruct {
delay = Duration.seconds(configuration.delay);
}

if (configuration.batchSize !== undefined) {
if (configuration.batchSize > 10 && configuration.fifo === true) {
throw new ServerlessError(
`Invalid configuration in 'constructs.${this.id}': 'batchSize' must be between 0 and 10 for FIFO queues, '${configuration.batchSize}' given.`,
"LIFT_INVALID_CONSTRUCT_CONFIGURATION"
);
}
if (configuration.batchSize > 10 && !this.getMaximumBatchingWindow()) {
throw new ServerlessError(
`Invalid configuration in 'constructs.${
this.id
}': 'maxBatchingWindow' must be greater than 0 for batchSize > 10, '${this.getMaximumBatchingWindow()}' given.`,
"LIFT_INVALID_CONSTRUCT_CONFIGURATION"
);
}
}

let encryption = undefined;
if (isNil(configuration.encryption) || configuration.encryption.length === 0) {
encryption = {};
Expand Down
49 changes: 49 additions & 0 deletions test/unit/queues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,4 +700,53 @@ describe("queues", () => {
);
}
});

it("should throw if batch size is over 10 for FIFO queues", async () => {
expect.assertions(2);

try {
await runServerless({
fixture: "queues",
configExt: merge({}, pluginConfigExt, {
constructs: {
emails: {
batchSize: 100,
fifo: true,
},
},
}),
command: "package",
});
} catch (error) {
expect(error).toBeInstanceOf(ServerlessError);
expect(error).toHaveProperty(
"message",
"Invalid configuration in 'constructs.emails': 'batchSize' must be between 0 and 10 for FIFO queues, '100' given."
);
}
});

it("should throw if batch size is over 10 and maxBatchWindow is not set", async () => {
expect.assertions(2);

try {
await runServerless({
fixture: "queues",
configExt: merge({}, pluginConfigExt, {
constructs: {
emails: {
batchSize: 100,
},
},
}),
command: "package",
});
} catch (error) {
expect(error).toBeInstanceOf(ServerlessError);
expect(error).toHaveProperty(
"message",
"Invalid configuration in 'constructs.emails': 'maxBatchingWindow' must be greater than 0 for batchSize > 10, '0' given."
);
}
});
});