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

chore(sdk): update queue.push() to use variadic parameter for messages #3746

Merged
merged 11 commits into from
Aug 17, 2023
8 changes: 4 additions & 4 deletions docs/docs/04-standard-library/01-cloud/queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ new cloud.Queue(props?: QueueProps);
| <code><a href="#@winglang/sdk.cloud.IQueueClient.approxSize">approxSize</a></code> | Retrieve the approximate number of messages in the queue. |
| <code><a href="#@winglang/sdk.cloud.IQueueClient.pop">pop</a></code> | Pop a message from the queue. |
| <code><a href="#@winglang/sdk.cloud.IQueueClient.purge">purge</a></code> | Purge all of the messages in the queue. |
| <code><a href="#@winglang/sdk.cloud.IQueueClient.push">push</a></code> | Push a message to the queue. |
| <code><a href="#@winglang/sdk.cloud.IQueueClient.push">push</a></code> | Push one or more messages to the queue. |

---

Expand Down Expand Up @@ -172,12 +172,12 @@ Purge all of the messages in the queue.
##### `push` <a name="push" id="@winglang/sdk.cloud.IQueueClient.push"></a>

```wing
inflight push(message: str): void
inflight push(messages: str): void
garysassano marked this conversation as resolved.
Show resolved Hide resolved
```

Push a message to the queue.
Push one or more messages to the queue.

###### `message`<sup>Required</sup> <a name="message" id="@winglang/sdk.cloud.IQueueClient.push.parameter.message"></a>
###### `messages`<sup>Required</sup> <a name="messages" id="@winglang/sdk.cloud.IQueueClient.push.parameter.messages"></a>

- *Type:* str

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ source: libs/wingc/src/lsp/completions.rs
kind: 8
documentation:
kind: markdown
value: "```wing\ninterface IQueueClient\n```\n---\nInflight interface for `Queue`.\n### Methods\n- `approxSize` — Retrieve the approximate number of messages in the queue.\n- `pop` — Pop a message from the queue.\n- `purge` — Purge all of the messages in the queue.\n- `push` — Push a message to the queue."
value: "```wing\ninterface IQueueClient\n```\n---\nInflight interface for `Queue`.\n### Methods\n- `approxSize` — Retrieve the approximate number of messages in the queue.\n- `pop` — Pop a message from the queue.\n- `purge` — Purge all of the messages in the queue.\n- `push` — Push one or more messages to the queue."
sortText: ii|IQueueClient
- label: IQueueSetConsumerHandler
kind: 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ source: libs/wingc/src/lsp/completions.rs
kind: 8
documentation:
kind: markdown
value: "```wing\ninterface IQueueClient\n```\n---\nInflight interface for `Queue`.\n### Methods\n- `approxSize` — Retrieve the approximate number of messages in the queue.\n- `pop` — Pop a message from the queue.\n- `purge` — Purge all of the messages in the queue.\n- `push` — Push a message to the queue."
value: "```wing\ninterface IQueueClient\n```\n---\nInflight interface for `Queue`.\n### Methods\n- `approxSize` — Retrieve the approximate number of messages in the queue.\n- `pop` — Pop a message from the queue.\n- `purge` — Purge all of the messages in the queue.\n- `push` — Push one or more messages to the queue."
sortText: ii|IQueueClient
- label: IQueueSetConsumerHandler
kind: 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ source: libs/wingc/src/lsp/completions.rs
kind: 8
documentation:
kind: markdown
value: "```wing\ninterface IQueueClient\n```\n---\nInflight interface for `Queue`.\n### Methods\n- `approxSize` — Retrieve the approximate number of messages in the queue.\n- `pop` — Pop a message from the queue.\n- `purge` — Purge all of the messages in the queue.\n- `push` — Push a message to the queue."
value: "```wing\ninterface IQueueClient\n```\n---\nInflight interface for `Queue`.\n### Methods\n- `approxSize` — Retrieve the approximate number of messages in the queue.\n- `pop` — Pop a message from the queue.\n- `purge` — Purge all of the messages in the queue.\n- `push` — Push one or more messages to the queue."
sortText: ii|IQueueClient
- label: IQueueSetConsumerHandler
kind: 8
Expand Down
6 changes: 3 additions & 3 deletions libs/wingsdk/src/cloud/queue.ts
garysassano marked this conversation as resolved.
Show resolved Hide resolved
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));
},
});
garysassano marked this conversation as resolved.
Show resolved Hide resolved
});
garysassano marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
Loading