Examples
Schedules
You can run the async code by importing AsyncQStash
from qstash
and awaiting the methods.
Create a schedule that runs every 5 minutes
from qstash import QStash
client = QStash("<QSTASH-TOKEN>")
schedule_id = client.schedule.create(
destination="https://my-api...",
cron="*/5 * * * *",
)
print(schedule_id)
Create a schedule that runs every hour and sends the result to a callback URL
from qstash import QStash
client = QStash("<QSTASH-TOKEN>")
client.schedule.create(
destination="https://my-api...",
cron="0 * * * *",
callback="https://my-callback...",
failure_callback="https://my-failure-callback...",
)
Create a schedule to a URL group that runs every minute
from qstash import QStash
client = QStash("<QSTASH-TOKEN>")
client.schedule.create(
destination="my-url-group",
cron="0 * * * *",
)
Get a schedule by schedule id
from qstash import QStash
client = QStash("<QSTASH-TOKEN>")
schedule = client.schedule.get("<schedule-id>")
print(schedule.cron)
List all schedules
from qstash import QStash
client = QStash("<QSTASH-TOKEN>")
all_schedules = client.schedule.list()
print(all_schedules)
Delete a schedule
from qstash import QStash
client = QStash("<QSTASH-TOKEN>")
client.schedule.delete("<schedule-id>")
Create a schedule with timeout
Timeout value to use when calling a schedule URL (See Upstash-Timeout
in Create Schedule page).
from qstash import QStash
client = QStash("<QSTASH-TOKEN>")
schedule_id = client.schedule.create(
destination="https://my-api...",
cron="*/5 * * * *",
timeout="30s",
)
print(schedule_id)
Pause/Resume a schedule
from qstash import QStash
client = QStash("<QSTASH-TOKEN>")
schedule_id = "scd_1234"
client.schedule.pause(schedule_id)
schedule = client.schedule.get(schedule_id)
print(schedule.paused) # prints True
client.schedule.resume(schedule_id)
Was this page helpful?