Skip to content

Commit

Permalink
Qstash-js: Add pause resume schedule & queue docs and timeout docs
Browse files Browse the repository at this point in the history
* feat: add pause resume schedule & queue docs and timeout docs

the changes reflect the last two changes in upstash/qstash-js#109

* feat: add qstash-js messages deleteMany & deletAll examples

the changes we document are in:
- PR upstash/qstash-js#114
- commit upstash/qstash-js@dd93920

* fix: update according to reviews
  • Loading branch information
CahidArda authored Jul 19, 2024
1 parent 374169c commit 246c834
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 2 deletions.
3 changes: 2 additions & 1 deletion mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,8 @@
"oss/sdks/ts/qstash/examples/dlq",
"oss/sdks/ts/qstash/examples/events",
"oss/sdks/ts/qstash/examples/messages",
"oss/sdks/ts/qstash/examples/receiver"
"oss/sdks/ts/qstash/examples/receiver",
"oss/sdks/ts/qstash/examples/queues"
]
}
]
Expand Down
20 changes: 20 additions & 0 deletions oss/sdks/ts/qstash/examples/messages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,23 @@ const client = new Client({ token: "<QSTASH_TOKEN>" });
const messages = client.messages
const msg = await messages.delete("msgId");
```

#### Cancel messages in bulk

Cancel many messages at once or cancel all messages

```typescript
import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });

// deleting two messages at once
await client.messages.deleteMany([
"message-id-1",
"message-id-2",
])


// deleting all messages
await client.messages.deleteAll()
```
15 changes: 15 additions & 0 deletions oss/sdks/ts/qstash/examples/publish.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,18 @@ const res = await client.publishJSON({
contentBasedDeduplication: true,
});
```

#### Publish a message with timeout

Timeout value in seconds to use when calling a url ([See `Upstash-Timeout` in Publish Message page](/qstash/api/publish#request))

```typescript
import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });
const res = await client.publishJSON({
url: "https://my-api...",
body: { hello: "world" },
timeout: 30 // 30 seconds timeout
});
```
45 changes: 45 additions & 0 deletions oss/sdks/ts/qstash/examples/queues.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: Queues
---

#### Create a queue with parallelism 2

```typescript
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });

const queueName = "upstash-queue";
await client.queue({ queueName }).upsert({ parallelism: 2 });

const queueDetails = await client.queue({ queueName }).get();
```

#### Delete Queue

```typescript
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });

const queueName = "upstash-queue";
await client.queue({ queueName: queueName }).delete();
```

#### Pause/Resume a queue

```typescript
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });

const name = "upstash-pause-resume-queue";
const queue = client.queue({ queueName: name });
await queue.upsert({ parallelism: 1 });

// pause queue
await queue.pause();

const queueInfo = await queue.get();
console.log(queueInfo.paused); // prints true

// resume queue
await queue.resume();
```
34 changes: 34 additions & 0 deletions oss/sdks/ts/qstash/examples/schedules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,37 @@ const client = new Client({ token: "<QSTASH_TOKEN>" });
const schedules = client.schedules();
await schedules.delete("scheduleId");
```

#### Create a schedule with timeout

Timeout value in seconds to use when calling a schedule URL ([See `Upstash-Timeout` in Create Schedule page](/qstash/api/schedules/create)).

```typescript
import { Client } from "@upstash/qstash";

const client = new Client({ token: "<QSTASH_TOKEN>" });
const schedules = client.schedules();
await schedules.create({
url: "https://my-api...",
cron: "* * * * *",
timeout: 30 // 30 seconds timeout
});
```

#### Pause/Resume a schedule

```typescript
import { Client } from "@upstash/qstash";
const client = new Client({ token: "<QSTASH_TOKEN>" });
const scheduleId = "my-schedule"

// pause schedule
await client.schedules.pause({ schedule: scheduleId });

// check if paused
const result = await client.schedules.get(scheduleId);
console.log(getResult.isPaused) // prints true

// resume schedule
await client.schedules.resume({ schedule: scheduleId });
```
2 changes: 1 addition & 1 deletion qstash/howto/receiving.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ In addition to your custom headers, we're sending these headers as well:
| ----------------------| -------------------------------------------------------------------- |
| `User-Agent` | Will be set to `Upstash-QStash` |
| `Content-Type` | The original `Content-Type` header |
| `Upstash-Topic-Name` | The URL Group name if sent to a URL Group |
| `Upstash-Topic-Name` | The URL Group name if sent to a URL Group |
| `Upstash-Signature` | The signature you need to verify [See here](/qstash/howto/signature) |
| `Upstash-Retried` | How often the message has been retried so far. Starts with 0. |
| `Upstash-Message-Id` | The message id of the message. |
Expand Down

0 comments on commit 246c834

Please sign in to comment.