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

Update QStash Python SDK docs #194

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@
]
},
{
"group": "upstash-qstash",
"group": "qstash",
"pages": [
"oss/sdks/py/qstash/overview",
"oss/sdks/py/qstash/gettingstarted",
Expand All @@ -1338,12 +1338,13 @@
"oss/sdks/py/qstash/examples/overview",
"oss/sdks/py/qstash/examples/publish",
"oss/sdks/py/qstash/examples/schedules",
"oss/sdks/py/qstash/examples/topics",
"oss/sdks/py/qstash/examples/url-groups",
"oss/sdks/py/qstash/examples/dlq",
"oss/sdks/py/qstash/examples/events",
"oss/sdks/py/qstash/examples/messages",
"oss/sdks/py/qstash/examples/keys",
"oss/sdks/py/qstash/examples/receiver"
"oss/sdks/py/qstash/examples/receiver",
"oss/sdks/py/qstash/examples/queues"
]
}
]
Expand Down
29 changes: 15 additions & 14 deletions oss/sdks/py/qstash/examples/dlq.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: DLQ
---

<Info>
You can run the async code by importing `Client` from `upstash_qstash.asyncio`
You can run the async code by importing `AsyncQStash` from `qstash`
and awaiting the methods.
</Info>

Expand All @@ -13,33 +13,34 @@ Since the DLQ can have a large number of messages, they are paginated.
You can go through the results using the `cursor`.

```python
from upstash_qstash import Client
from qstash import QStash

client = QStash("<QSTASH-TOKEN>")

dlq = client.dlq()
all_messages = []
cursor = None
while True:
res = dlq.list_messages({"cursor": cursor})
all_messages.extend(res["messages"])
cursor = res.get("cursor")
if cursor is None:
break
res = client.dlq.list(cursor=cursor)
all_messages.extend(res.messages)
cursor = res.cursor
if cursor is None:
break
```

#### Get a message from the DLQ

```python
from upstash_qstash import Client
from qstash import QStash

dlq = client.dlq()
msg = dlq.get("dlqId")
client = QStash("<QSTASH-TOKEN>")
msg = client.dlq.get("<dlq-id>")
```

#### Delete a message from the DLQ

```python
from upstash_qstash import Client
from qstash import QStash

dlq = client.dlq()
dlq.delete("dlqId")
client = QStash("<QSTASH-TOKEN>")
client.dlq.delete("<dlq-id>")
```
17 changes: 9 additions & 8 deletions oss/sdks/py/qstash/examples/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Events
---

<Info>
You can run the async code by importing `Client` from `upstash_qstash.asyncio`
You can run the async code by importing `AsyncQStash` from `qstash`
and awaiting the methods.
</Info>

Expand All @@ -13,15 +13,16 @@ Since there can be a large number of events, they are paginated.
You can go through the results using the `cursor`.

```python
from upstash_qstash import Client
from qstash import QStash

client = QStash("<QSTASH-TOKEN>")

client = Client("<QSTASH_TOKEN>")
all_events = []
cursor = None
while True:
res = client.events({"cursor": cursor})
all_events.extend(res["events"])
cursor = res.get("cursor")
if cursor is None:
break
res = client.event.list(cursor=cursor)
all_events.extend(res.events)
cursor = res.cursor
if cursor is None:
break
```
21 changes: 10 additions & 11 deletions oss/sdks/py/qstash/examples/keys.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@ title: Keys
---

<Info>
You can run the async code by importing `Client` from `upstash_qstash.asyncio`
You can run the async code by importing `AsyncQStash` from `qstash`
and awaiting the methods.
</Info>

#### Retrieve your signing Keys

```python
from upstash_qstash import Client
from qstash import QStash

client = Client("<QSTASH_TOKEN>")
keys = client.keys()
both_keys = keys.get()
client = QStash("<QSTASH-TOKEN>")
signing_key = client.signing_key.get()

print(both_keys["current"], both_keys["next"])
print(signing_key.current, signing_key.next)
```

#### Rotate your signing Keys

```python
from upstash_qstash import Client
from qstash import QStash

client = Client("<QSTASH_TOKEN>")
keys = client.keys()
new_keys = keys.rotate()
print(new_keys["current"], new_keys["next"])
client = QStash("<QSTASH-TOKEN>")
new_signing_key = client.signing_key.rotate()

print(new_signing_key.current, new_signing_key.next)
```
32 changes: 23 additions & 9 deletions oss/sdks/py/qstash/examples/messages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Messages
---

<Info>
You can run the async code by importing `Client` from `upstash_qstash.asyncio`
You can run the async code by importing `AsyncQStash` from `qstash`
and awaiting the methods.
</Info>

Expand All @@ -14,19 +14,33 @@ for accessing messages that are in the process of being delivered/retried.
#### Retrieve a message

```python
from upstash_qstash import Client
from qstash import QStash

client = Client("<QSTASH_TOKEN>")
messages = client.messages()
msg = messages.get("msg_id")
client = QStash("<QSTASH-TOKEN>")
msg = client.message.get("<msg-id>")
```

#### Cancel/delete a message

```python
from upstash_qstash import Client
from qstash import QStash

client = Client("<QSTASH_TOKEN>")
messages = client.messages()
msg = messages.delete("msg_id")
client = QStash("<QSTASH-TOKEN>")
client.message.cancel("<msg-id>")
```

#### Cancel messages in bulk

Cancel many messages at once or cancel all messages

```python
from qstash import QStash

client = QStash("<QSTASH-TOKEN>")

# cancel more than one message
client.message.cancel_many(["<msg-id-0>", "<msg-id-1>"])

# cancel all messages
client.message.cancel_all()
```
2 changes: 1 addition & 1 deletion oss/sdks/py/qstash/examples/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ title: Overview
---

These are example usages of each method in the QStash SDK. You can also reference the
[examples repo](https://github.com/upstash/qstash-python/tree/main/examples) and [API examples](/qstash/overall/apiexamples) for more.
[examples repo](https://github.com/upstash/qstash-py/tree/main/examples) and [API examples](/qstash/overall/apiexamples) for more.
Loading