Skip to content

Commit

Permalink
Merge pull request #317 from joawan/master
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli authored Jun 16, 2023
2 parents aaa3588 + 1cdc132 commit 1e786ed
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,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 @@ -701,4 +701,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."
);
}
});
});

0 comments on commit 1e786ed

Please sign in to comment.