Scheduling
Cron jobs, message queues and outbound webhooks.
Overview
Base path:
/v1/schedulingPython namespace:
infra.crontext
# Python
from infrai import infra
# TypeScript
import { InfraiClient } from "@infrai/sdk";
const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });
// → client.jobMethods
scheduling.cron.create
POST /v1/scheduling/cron
Create a scheduled cron job that POSTs to a URL on a schedule.
Python
python
infra.cron.create(cron_expr, task, *, name=None, timezone="UTC", retry=3, timeout_seconds=300, payload=None, idempotency_key=...)TypeScript
typescript
client.job.cron.create(opts: CronOptions): Promise<CronRecord>Parameters
| Name | Type | Required | Description |
|---|---|---|---|
name | string | Required | Human-readable job name. |
schedule | string | Required | Cron expression, e.g. 0 9 * * *. |
url | string | Required | URL that receives the scheduled POST. |
payload | unknown | Optional | Optional JSON payload sent with each run. |
timezone | string | Optional | IANA timezone for the schedule. |
retries | number | Optional | Retry attempts on failure. |
idempotency_key | string | Optional | Optional dedup key; identical retries return the same result. |
Returns
CronRecord { cron_id, name, schedule, url, enabled, next_run_at? }Example
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
job = infra.cron.create(
"0 9 * * *", # every day at 09:00
"send-daily-digest",
name="daily-digest",
timezone="UTC",
payload={"segment": "active-users"},
)
print("cron_id:", job.get("id") or job.get("cron_id"))scheduling.cron.list
GET /v1/scheduling/cron
List cron jobs.
Python
python
infra.cron.list()TypeScript
typescript
// see ROUTES["scheduling.cron.list"]Returns
{ items: CronRecord[] }Example
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
for j in infra.cron.list().get("items", []):
print(j.get("cron_id"), j.get("schedule"), "next:", j.get("next_run_at"))scheduling.queue.publish
POST /v1/scheduling/queue/publish
Publish a message to a queue, optionally delayed.
Python
python
infra.queue.publish(queue, payload, *, delay_seconds=None, idempotency_key=None)TypeScript
typescript
// see ROUTES["scheduling.queue.publish"]Parameters
| Name | Type | Required | Description |
|---|---|---|---|
queue | string | Required | The queue name. |
payload | object | Required | Message payload. |
delay_seconds | number | Optional | Delay before delivery in seconds. |
idempotency_key | string | Optional | Optional dedup key; identical retries return the same result. |
Returns
{ message_id }Example
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
msg = infra.queue.publish(
"send-daily-digest",
{"user_id": "u_123", "kind": "manual-trigger"},
delay_seconds=0,
)
print("message_id:", msg.get("message_id") or msg.get("id"))scheduling.webhook.send
POST /v1/scheduling/webhook/send
Send an outbound webhook with retries and HMAC signing.
Python
python
infra.webhook.send(url, payload, ...)TypeScript
typescript
// see ROUTES["scheduling.webhook.send"]Parameters
| Name | Type | Required | Description |
|---|---|---|---|
url | string | Required | Destination URL for the webhook. |
payload | object | Required | Message payload. |
Returns
{ delivery_id, state }Example
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
d = infra.webhook.send("https://api.example.com/hooks/order",
{"order_id": "ord_42", "status": "paid"})
print("delivery:", d.get("delivery_id"), "| state:", d.get("state"))