From cd41a5373ac78003783f1349f322740c760fb15e Mon Sep 17 00:00:00 2001 From: Gary Sassano <10464497+garysassano@users.noreply.github.com> Date: Wed, 9 Aug 2023 01:25:54 +0200 Subject: [PATCH] update Queue.push to use variadic parameter for messages --- libs/wingsdk/src/cloud/queue.ts | 6 +++--- libs/wingsdk/src/shared-aws/queue.inflight.ts | 12 +++++++----- libs/wingsdk/src/target-sim/queue.inflight.ts | 16 +++++++++------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/libs/wingsdk/src/cloud/queue.ts b/libs/wingsdk/src/cloud/queue.ts index 357e7aeb15a..0b1cb48c7cc 100644 --- a/libs/wingsdk/src/cloud/queue.ts +++ b/libs/wingsdk/src/cloud/queue.ts @@ -91,11 +91,11 @@ export interface QueueSetConsumerProps extends FunctionProps { */ export interface IQueueClient { /** - * Push a message to the queue. - * @param message Payload to send to the queue. + * Push one or more messages to the queue. + * @param messages Payload to send to the queue. * @inflight */ - push(message: string): Promise; + push(...messages: string[]): Promise; /** * Purge all of the messages in the queue. diff --git a/libs/wingsdk/src/shared-aws/queue.inflight.ts b/libs/wingsdk/src/shared-aws/queue.inflight.ts index 7001687a18b..10a8ad52a08 100644 --- a/libs/wingsdk/src/shared-aws/queue.inflight.ts +++ b/libs/wingsdk/src/shared-aws/queue.inflight.ts @@ -13,12 +13,14 @@ export class QueueClient implements IQueueClient { private readonly client: SQSClient = new SQSClient({}) ) {} - public async push(message: string): Promise { - const command = new SendMessageCommand({ - QueueUrl: this.queueUrl, - MessageBody: message, + public async push(...messages: string[]): Promise { + messages.forEach(async (message) => { + const command = new SendMessageCommand({ + QueueUrl: this.queueUrl, + MessageBody: message, + }); + await this.client.send(command); }); - await this.client.send(command); } public async purge(): Promise { diff --git a/libs/wingsdk/src/target-sim/queue.inflight.ts b/libs/wingsdk/src/target-sim/queue.inflight.ts index 126736c103a..236f1dec9f6 100644 --- a/libs/wingsdk/src/target-sim/queue.inflight.ts +++ b/libs/wingsdk/src/target-sim/queue.inflight.ts @@ -58,13 +58,15 @@ export class Queue this.subscribers.push(s); } - public async push(message: string): Promise { - // TODO: enforce maximum queue message size? - return this.context.withTrace({ - message: `Push (message=${message}).`, - activity: async () => { - this.messages.push(new QueueMessage(this.retentionPeriod, message)); - }, + // TODO: enforce maximum queue message size? + public async push(...messages: string[]): Promise { + messages.forEach(async (message) => { + await this.context.withTrace({ + message: `Push (message=${message}).`, + activity: async () => { + this.messages.push(new QueueMessage(this.retentionPeriod, message)); + }, + }); }); }