Skip to content

Scheduling

Cron jobs, message queues and outbound webhooks.

Overview

Base path: /v1/scheduling
Python namespace: infra.cron
text
# Python
from infrai import infra

# TypeScript
import { InfraiClient } from "@infrai/sdk";
const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });
// → client.job

Methods

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

NameTypeRequiredDescription
namestring
Required
Human-readable job name.
schedulestring
Required
Cron expression, e.g. 0 9 * * *.
urlstring
Required
URL that receives the scheduled POST.
payloadunknownOptionalOptional JSON payload sent with each run.
timezonestringOptionalIANA timezone for the schedule.
retriesnumberOptionalRetry attempts on failure.
idempotency_keystringOptionalOptional 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

NameTypeRequiredDescription
queuestring
Required
The queue name.
payloadobject
Required
Message payload.
delay_secondsnumberOptionalDelay before delivery in seconds.
idempotency_keystringOptionalOptional 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

NameTypeRequiredDescription
urlstring
Required
Destination URL for the webhook.
payloadobject
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"))