Skip to content

Commit

Permalink
update Queue.push to use variadic parameter for messages
Browse files Browse the repository at this point in the history
  • Loading branch information
garysassano committed Aug 8, 2023
1 parent 6ae93e3 commit cd41a53
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions libs/wingsdk/src/cloud/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
push(...messages: string[]): Promise<void>;

/**
* Purge all of the messages in the queue.
Expand Down
12 changes: 7 additions & 5 deletions libs/wingsdk/src/shared-aws/queue.inflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export class QueueClient implements IQueueClient {
private readonly client: SQSClient = new SQSClient({})
) {}

public async push(message: string): Promise<void> {
const command = new SendMessageCommand({
QueueUrl: this.queueUrl,
MessageBody: message,
public async push(...messages: string[]): Promise<void> {
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<void> {
Expand Down
16 changes: 9 additions & 7 deletions libs/wingsdk/src/target-sim/queue.inflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ export class Queue
this.subscribers.push(s);
}

public async push(message: string): Promise<void> {
// 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<void> {
messages.forEach(async (message) => {
await this.context.withTrace({
message: `Push (message=${message}).`,
activity: async () => {
this.messages.push(new QueueMessage(this.retentionPeriod, message));
},
});
});
}

Expand Down

0 comments on commit cd41a53

Please sign in to comment.