定时任务 Cron
按 cron 表达式调度周期性 HTTP 任务——创建、暂停、手动触发并查看运行记录,支持重试与保留期。
概览
基础路径:
https://api.infrai.cc/v1/cron鉴权头:
Authorization: Bearer $INFRAI_API_KEYbash
# Call any /v1/cron capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/cron/... \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json"方法
cron.create
POST /v1/cron/create
创建按计划向 URL 发起 POST 的定时任务。
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
name | string | 必填 | 可读的任务名称。 |
schedule | string | 必填 | Cron 表达式,例如 0 9 * * *。 |
run_at | string | 可选 | 一次性任务的绝对 ISO-8601 UTC 触发时间,仅触发一次(与周期 schedule 二选一)。 |
url | string | 必填 | 接收定时 POST 的 URL。 |
payload | unknown | 可选 | 每次运行附带的可选 JSON 负载。 |
timezone | string | 可选 | 调度使用的 IANA 时区。 |
retries | number | 可选 | 失败时的重试次数。 |
idempotency_key | string | 可选 | 可选去重 key;相同重试将返回同一结果。 |
返回
CronRecord { cron_id, name, schedule, url, enabled, next_run_at? }示例
一次性前置(每个范例都假定已完成):
bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."bash
curl -X POST https://api.infrai.cc/v1/cron/create \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"cron_expr": "0 9 * * 1", "task_type": "http_url", "task_url": "https://api.acme.com/weekly"}'python
import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/cron/create",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'cron_expr': '0 9 * * 1', 'task_type': 'http_url', 'task_url': 'https://api.acme.com/weekly'},
)
resp.raise_for_status()
print(resp.json())javascript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/create",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"cron_expr": "0 9 * * 1", "task_type": "http_url", "task_url": "https://api.acme.com/weekly"}),
},
);
console.log(await resp.json());typescript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/create",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"cron_expr": "0 9 * * 1", "task_type": "http_url", "task_url": "https://api.acme.com/weekly"}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cron.list
GET /v1/cron/list
列出定时任务。
返回
{ items: CronRecord[] }示例
一次性前置(每个范例都假定已完成):
bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."bash
curl -X GET https://api.infrai.cc/v1/cron/list \
-H "Authorization: Bearer $INFRAI_API_KEY"python
import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/cron/list",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())javascript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/list",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());typescript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/list",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cron.get
GET /v1/cron/get/{id}
获取单个定时任务的配置与下次运行时间
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
cron_id | string | 必填 | 定时任务 ID |
返回
CronRecord { cron_id, name, cron_expr, task, timezone, enabled, next_run_at? }示例
一次性前置(每个范例都假定已完成):
bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."bash
curl -X GET https://api.infrai.cc/v1/cron/get/ID \
-H "Authorization: Bearer $INFRAI_API_KEY"python
import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/cron/get/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())javascript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/get/ID",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());typescript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/get/ID",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cron.update
PATCH /v1/cron/update/{id}
更新定时任务的表达式、目标与策略
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
cron_id | string | 必填 | 定时任务 ID |
cron_expr | string | 可选 | 标准 5/6 段 cron 表达式 |
task | string | 可选 | 触发时投递的目标 URL |
name | string | 可选 | 任务名称 |
timezone | string | 可选 | IANA 时区名(如 Asia/Shanghai) |
retry | number | 可选 | 失败重试次数(0-10) |
timeout_seconds | number | 可选 | 单次触发超时秒数(1-900) |
overlap_policy | "allow" | "skip" | "queue" | 可选 | 重叠策略:allow 允许 / skip 跳过 / queue 排队 |
max_runs | number | 可选 | 最大运行次数,达到后自动停止 |
payload | object | 可选 | 随触发发送的 JSON 负载 |
headers | object | 可选 | 随触发发送的自定义请求头 |
on_failure_webhook | string | 可选 | 失败时回调的 Webhook 地址 |
idempotency_key | string | 可选 | 幂等键,避免重复执行 |
返回
CronRecord { cron_id, name, cron_expr, task, timezone, enabled, next_run_at? }示例
一次性前置(每个范例都假定已完成):
bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."bash
curl -X PATCH https://api.infrai.cc/v1/cron/update/ID \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'python
import os, requests
resp = requests.patch(
"https://api.infrai.cc/v1/cron/update/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={},
)
resp.raise_for_status()
print(resp.json())javascript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/update/ID",
{
method: "PATCH",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
},
);
console.log(await resp.json());typescript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/update/ID",
{
method: "PATCH",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cron.delete
DELETE /v1/cron/delete/{id}
删除一个定时任务
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
cron_id | string | 必填 | 定时任务 ID |
idempotency_key | string | 可选 | 幂等键,避免重复执行 |
返回
{ cron_id, deleted }示例
一次性前置(每个范例都假定已完成):
bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."bash
curl -X DELETE https://api.infrai.cc/v1/cron/delete/ID \
-H "Authorization: Bearer $INFRAI_API_KEY"python
import os, requests
resp = requests.delete(
"https://api.infrai.cc/v1/cron/delete/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())javascript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/delete/ID",
{
method: "DELETE",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());typescript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/delete/ID",
{
method: "DELETE",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cron.pause
POST /v1/cron/pause/{id}
暂停定时任务
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
cron_id | string | 必填 | 定时任务 ID |
idempotency_key | string | 可选 | 幂等键,避免重复执行 |
返回
CronRecord { cron_id, enabled }示例
一次性前置(每个范例都假定已完成):
bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."bash
curl -X POST https://api.infrai.cc/v1/cron/pause/ID \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"cron_id": "..."}'python
import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/cron/pause/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'cron_id': '...'},
)
resp.raise_for_status()
print(resp.json())javascript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/pause/ID",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"cron_id": "..."}),
},
);
console.log(await resp.json());typescript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/pause/ID",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"cron_id": "..."}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cron.resume
POST /v1/cron/resume/{id}
恢复已暂停的定时任务
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
cron_id | string | 必填 | 定时任务 ID |
idempotency_key | string | 可选 | 幂等键,避免重复执行 |
返回
CronRecord { cron_id, enabled, next_run_at? }示例
一次性前置(每个范例都假定已完成):
bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."bash
curl -X POST https://api.infrai.cc/v1/cron/resume/ID \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"cron_id": "..."}'python
import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/cron/resume/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'cron_id': '...'},
)
resp.raise_for_status()
print(resp.json())javascript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/resume/ID",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"cron_id": "..."}),
},
);
console.log(await resp.json());typescript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/resume/ID",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"cron_id": "..."}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cron.trigger
POST /v1/cron/trigger/{id}
立即手动触发一次定时任务运行
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
cron_id | string | 必填 | 定时任务 ID |
idempotency_key | string | 可选 | 幂等键,避免重复执行 |
返回
CronRun { run_id, cron_id, state, started_at }示例
一次性前置(每个范例都假定已完成):
bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."bash
curl -X POST https://api.infrai.cc/v1/cron/trigger/ID \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"job_id": "cron_01HX..."}'python
import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/cron/trigger/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'job_id': 'cron_01HX...'},
)
resp.raise_for_status()
print(resp.json())javascript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/trigger/ID",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"job_id": "cron_01HX..."}),
},
);
console.log(await resp.json());typescript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/trigger/ID",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"job_id": "cron_01HX..."}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cron.runs.get
GET /v1/cron/runs/get/{id}/{run_id}
获取定时任务某次运行的详情
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
cron_id | string | 必填 | 定时任务 ID |
run_id | string | 必填 | 运行(CronRun)ID |
返回
CronRun { run_id, cron_id, state, started_at, finished_at?, response_status?, error? }示例
一次性前置(每个范例都假定已完成):
bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."bash
curl -X GET https://api.infrai.cc/v1/cron/runs/get/ID/RUN_ID \
-H "Authorization: Bearer $INFRAI_API_KEY"python
import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/cron/runs/get/ID/RUN_ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())javascript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/runs/get/ID/RUN_ID",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());typescript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/runs/get/ID/RUN_ID",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cron.runs.list
GET /v1/cron/runs/list/{id}
列出某定时任务的运行历史(执行记录),支持分页。
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
cron_id | string | 必填 | 要列出运行记录的定时任务 ID。 |
cursor | string | 可选 | 分页游标。 |
limit | number | 可选 | 返回运行记录的最大条数。 |
返回
{ items: CronRun[], next_cursor? }示例
一次性前置(每个范例都假定已完成):
bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."bash
curl -X GET https://api.infrai.cc/v1/cron/runs/list/ID \
-H "Authorization: Bearer $INFRAI_API_KEY"python
import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/cron/runs/list/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())javascript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/runs/list/ID",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());typescript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/runs/list/ID",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cron.retention.get
GET /v1/cron/retention/get/{id}
查询定时任务运行历史保留天数
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
cron_id | string | 必填 | 定时任务 ID |
返回
{ cron_id, retention_days }示例
一次性前置(每个范例都假定已完成):
bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."bash
curl -X GET https://api.infrai.cc/v1/cron/retention/get/ID \
-H "Authorization: Bearer $INFRAI_API_KEY"python
import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/cron/retention/get/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())javascript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/retention/get/ID",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());typescript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/retention/get/ID",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);cron.retention.set
PUT /v1/cron/retention/set/{id}
设置定时任务运行历史保留天数
参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
cron_id | string | 必填 | 定时任务 ID |
retention_days | number | 必填 | 保留的运行历史天数 |
idempotency_key | string | 可选 | 幂等键,避免重复执行 |
返回
{ cron_id, retention_days }示例
一次性前置(每个范例都假定已完成):
bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."bash
curl -X PUT https://api.infrai.cc/v1/cron/retention/set/ID \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"retention_days": 0}'python
import os, requests
resp = requests.put(
"https://api.infrai.cc/v1/cron/retention/set/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'retention_days': 0},
)
resp.raise_for_status()
print(resp.json())javascript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/retention/set/ID",
{
method: "PUT",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"retention_days": 0}),
},
);
console.log(await resp.json());typescript
const resp = await fetch(
"https://api.infrai.cc/v1/cron/retention/set/ID",
{
method: "PUT",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"retention_days": 0}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);全部能力
本模块全部已路由能力——完整的对外 REST 契约。上方方法是带讲解的入门示例,此表是完整参考。
| 能力 | 端点 | 说明 |
|---|---|---|
cron.create | POST /v1/cron/create | Create a scheduled job: recurring via cron_expr, or a one-shot via run_at (fires once); idempotent write. |
cron.delete | DELETE /v1/cron/delete/{id} | Delete a cron job and stop all of its future scheduled runs; idempotent. |
cron.get | GET /v1/cron/get/{id} | Get a single cron job's configuration and next run time. |
cron.list | GET /v1/cron/list | List the account's cron jobs with pagination. |
cron.pause | POST /v1/cron/pause/{id} | Pause a cron job, halting subsequent triggers. |
cron.resume | POST /v1/cron/resume/{id} | Resume a paused cron job. |
cron.retention.get | GET /v1/cron/retention/get/{id} | Get the retention days for cron job run history. |
cron.retention.set | PUT /v1/cron/retention/set/{id} | Set the retention days for cron job run history. |
cron.runs.get | GET /v1/cron/runs/get/{id}/{run_id} | Retrieve details of a single cron job execution (CronRun). |
cron.runs.list | GET /v1/cron/runs/list/{id} | List a cron job's run history (executions) with pagination. |
cron.trigger | POST /v1/cron/trigger/{id} | Manually trigger an immediate run of a scheduled cron job. |
cron.update | PATCH /v1/cron/update/{id} | Update a cron job's schedule expression, target, overlap policy, and other fields. |
完整示例
本模块的生产级端到端范例:先一次性配置,再运行业务流程,尽量覆盖本模块的多数 API。
单文件可运行 Python 程序(仅标准库、无 SDK):拷贝后填入 INFRAI_API_KEY 运行,即可按真实业务流逐步体验本模块核心 API——每一步都真实调用并计费,后续步骤复用前一步返回的真实字段。12 行 helper 就是全部集成代码。
python
#!/usr/bin/env python3
"""Infrai · cron — runnable real-app example (single file, zero deps).
Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://infrai.cc/login (Google/
GitHub sign-in grants $2 free credit); add funds at
https://infrai.cc/billing. No SDK — the 12-line helper below is the
entire integration."""
import json
import os
from urllib import error, request
KEY = os.environ.get("INFRAI_API_KEY") or "ifr_..." # <- your key
BASE = "https://api.infrai.cc"
# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
req = request.Request(
BASE + path, method=method,
data=json.dumps(body).encode() if body is not None else None,
headers={"Authorization": f"Bearer {KEY}",
"Content-Type": "application/json"})
try:
with request.urlopen(req, timeout=60) as r:
return json.loads(r.read())
except error.HTTPError as e:
return json.loads(e.read())
def show(label, resp):
print(f"\n== {label} ==")
print(json.dumps(resp, indent=2, ensure_ascii=False))
return resp
# 1) cron.create — POST /v1/cron/create · Create a scheduled job: recurring via cron_expr, or a one-shot via run_at (fires once); idempotent write.
r1 = show("cron.create", infrai("POST", "/v1/cron/create", {"cron_expr":"0 9 * * 1","task_type":"http_url","task_url":"https://api.acme.com/weekly"}))
# 2) cron.runs.list — GET /v1/cron/runs/list/{id} · List a cron job's run history (executions) with pagination.
id_2 = (r1.get("data") or {}).get("cron_id") or ""
r2 = show("cron.runs.list", infrai("GET", f"/v1/cron/runs/list/{id_2}"))
# 3) cron.list — GET /v1/cron/list · List the account's cron jobs with pagination.
r3 = show("cron.list", infrai("GET", "/v1/cron/list"))
一次性前置(每个范例都假定已完成):
bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."bash
# 1) Auth: every call is a raw HTTPS request to the Infrai gateway carrying
# only your project key. No SDK, no install.
# Get your key: sign in with Google/GitHub at https://infrai.cc/login for a
# project key + $2 free credit (email sign-in starts at $0). On 402
# INSUFFICIENT_CREDIT, add funds at https://infrai.cc/billing (or POST
# /v1/account/topup and open the returned checkout_url).
export INFRAI_API_KEY="ifr_..." # from https://infrai.cc/login
# 2) cron.create
curl -X POST https://api.infrai.cc/v1/cron/create \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"cron_expr": "0 9 * * 1", "task_type": "http_url", "task_url": "https://api.acme.com/weekly"}'
# 3) cron.list
curl -X GET https://api.infrai.cc/v1/cron/list \
-H "Authorization: Bearer $INFRAI_API_KEY"
# 4) cron.get
curl -X GET https://api.infrai.cc/v1/cron/get/ID \
-H "Authorization: Bearer $INFRAI_API_KEY"
# 5) cron.update
curl -X PATCH https://api.infrai.cc/v1/cron/update/ID \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'
# 6) cron.delete
curl -X DELETE https://api.infrai.cc/v1/cron/delete/ID \
-H "Authorization: Bearer $INFRAI_API_KEY"
# 7) cron.pause
curl -X POST https://api.infrai.cc/v1/cron/pause/ID \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"cron_id": "..."}'
# 8) cron.resume
curl -X POST https://api.infrai.cc/v1/cron/resume/ID \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"cron_id": "..."}'
# 9) cron.trigger
curl -X POST https://api.infrai.cc/v1/cron/trigger/ID \
-H "Authorization: Bearer $INFRAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"job_id": "cron_01HX..."}'
python
# 1) Auth: every call is a raw HTTPS request carrying only your project key.
# No SDK to install — just the `requests` library.
import os, requests
BASE = "https://api.infrai.cc"
HEADERS = {
"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}",
"Content-Type": "application/json",
}
# 2) cron.create
import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/cron/create",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'cron_expr': '0 9 * * 1', 'task_type': 'http_url', 'task_url': 'https://api.acme.com/weekly'},
)
resp.raise_for_status()
print(resp.json())
# 3) cron.list
import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/cron/list",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())
# 4) cron.get
import os, requests
resp = requests.get(
"https://api.infrai.cc/v1/cron/get/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())
# 5) cron.update
import os, requests
resp = requests.patch(
"https://api.infrai.cc/v1/cron/update/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={},
)
resp.raise_for_status()
print(resp.json())
# 6) cron.delete
import os, requests
resp = requests.delete(
"https://api.infrai.cc/v1/cron/delete/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
)
resp.raise_for_status()
print(resp.json())
# 7) cron.pause
import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/cron/pause/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'cron_id': '...'},
)
resp.raise_for_status()
print(resp.json())
# 8) cron.resume
import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/cron/resume/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'cron_id': '...'},
)
resp.raise_for_status()
print(resp.json())
# 9) cron.trigger
import os, requests
resp = requests.post(
"https://api.infrai.cc/v1/cron/trigger/ID",
headers={"Authorization": f"Bearer {os.environ['INFRAI_API_KEY']}"},
json={'job_id': 'cron_01HX...'},
)
resp.raise_for_status()
print(resp.json())
javascript
// 1) Auth: every call is a raw HTTPS request carrying only your project key.
// No SDK to install — just the built-in fetch().
const BASE = "https://api.infrai.cc";
const HEADERS = {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
};
// 2) cron.create
const resp = await fetch(
"https://api.infrai.cc/v1/cron/create",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"cron_expr": "0 9 * * 1", "task_type": "http_url", "task_url": "https://api.acme.com/weekly"}),
},
);
console.log(await resp.json());
// 3) cron.list
const resp = await fetch(
"https://api.infrai.cc/v1/cron/list",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());
// 4) cron.get
const resp = await fetch(
"https://api.infrai.cc/v1/cron/get/ID",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());
// 5) cron.update
const resp = await fetch(
"https://api.infrai.cc/v1/cron/update/ID",
{
method: "PATCH",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
},
);
console.log(await resp.json());
// 6) cron.delete
const resp = await fetch(
"https://api.infrai.cc/v1/cron/delete/ID",
{
method: "DELETE",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
console.log(await resp.json());
// 7) cron.pause
const resp = await fetch(
"https://api.infrai.cc/v1/cron/pause/ID",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"cron_id": "..."}),
},
);
console.log(await resp.json());
// 8) cron.resume
const resp = await fetch(
"https://api.infrai.cc/v1/cron/resume/ID",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"cron_id": "..."}),
},
);
console.log(await resp.json());
// 9) cron.trigger
const resp = await fetch(
"https://api.infrai.cc/v1/cron/trigger/ID",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"job_id": "cron_01HX..."}),
},
);
console.log(await resp.json());
typescript
// 1) Auth: every call is a raw HTTPS request carrying only your project key.
// No SDK to install — just the built-in fetch(), typed.
const BASE = "https://api.infrai.cc";
const HEADERS: Record<string, string> = {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
};
// 2) cron.create
const resp = await fetch(
"https://api.infrai.cc/v1/cron/create",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"cron_expr": "0 9 * * 1", "task_type": "http_url", "task_url": "https://api.acme.com/weekly"}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 3) cron.list
const resp = await fetch(
"https://api.infrai.cc/v1/cron/list",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 4) cron.get
const resp = await fetch(
"https://api.infrai.cc/v1/cron/get/ID",
{
method: "GET",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 5) cron.update
const resp = await fetch(
"https://api.infrai.cc/v1/cron/update/ID",
{
method: "PATCH",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 6) cron.delete
const resp = await fetch(
"https://api.infrai.cc/v1/cron/delete/ID",
{
method: "DELETE",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
},
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 7) cron.pause
const resp = await fetch(
"https://api.infrai.cc/v1/cron/pause/ID",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"cron_id": "..."}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 8) cron.resume
const resp = await fetch(
"https://api.infrai.cc/v1/cron/resume/ID",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"cron_id": "..."}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);
// 9) cron.trigger
const resp = await fetch(
"https://api.infrai.cc/v1/cron/trigger/ID",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({"job_id": "cron_01HX..."}),
},
);
if (!resp.ok) throw new Error(`infrai ${resp.status}`);
const data: unknown = await resp.json();
console.log(data);