Scheduler API
Canonical reference: docs/api-reference.md (generated endpoint directory) — this page is a task-oriented summary.
Manage scheduled jobs for automated task execution. Supports cron, every
(recurring interval), and at (one-time timestamp) schedules, plus
natural-language scheduling and missed-job catch-up on restart.
The base path is singular:
/api/v1/schedule(not/schedules). All scheduler endpoints share this prefix. Job creation isPOST /api/v1/schedule/spawn(notPOST /api/v1/schedule).
Overview
The scheduler runs as a gen_server with an ETS-backed job store. Jobs are
attributed to the creating user (user_uuid) and dispatch tasks to workers at
the scheduled time. Most mutating endpoints require admin (the "*"
permission).
| Schedule Type | Field | Description | Use Case |
|---|---|---|---|
cron | cron | 5-field cron expression | Periodic tasks on a calendar schedule |
every | every | Interval in milliseconds (must be > 0) | Recurring tasks at fixed intervals |
at | at | One-time timestamp in ms | Delayed single execution |
Endpoints
List Scheduled Jobs
GET /api/v1/schedule
Returns all scheduled jobs. Admin-only — non-admin callers receive an empty paginated list (not an error). Paginated via the standard envelope.
Response (200):
{
"items": [
{
"id": 1,
"name": "Daily health check",
"schedule_type": "cron",
"cron_expr": "0 9 * * *",
"interval_ms": null,
"at_ms": null,
"next_run_ms": 1716192000000,
"last_run_ms": 1716105600000,
"status": "active",
"prompt": "Check system health and report any issues",
"model": "glm-5.1",
"opts": {},
"delete_after_run": false,
"consecutive_errors": 0,
"enabled": true,
"currently_running": false,
"tz": "UTC"
}
],
"total": 1,
"limit": 50,
"offset": 0,
"page": 1,
"total_pages": 1,
"has_more": false
}
Create a Scheduled Job
POST /api/v1/schedule/spawn
Create a new scheduled job. Admin-only (enforced by the {admin, require}
middleware scope, ).
Cron example:
{
"name": "Daily health check",
"prompt": "Check system health and report any issues",
"cron": "0 9 * * *",
"model": "glm-5.1",
"opts": {}
}
Every example:
{
"name": "Monitor queue depth",
"prompt": "Check ZMQ queue depth and alert if > 100",
"every": 300000
}
One-time example:
{
"name": "Deploy notification",
"prompt": "Announce deployment completion",
"at": 1716192000000,
"delete_after_run": true
}
Natural-language example (resolved server-side via sol_nl_schedule):
{
"name": "Weekly report",
"prompt": "Generate weekly system report",
"schedule": "every monday at 9am"
}
Request Fields
| Field | Required | Description |
|---|---|---|
prompt | Yes | Task prompt to send when the job fires. Empty → 400. |
name | No | Human-readable job name. |
cron | One of cron/every/at (or schedule) | 5-field cron expression. |
every | One of cron/every/at (or schedule) | Interval in ms (positive integer). |
at | One of cron/every/at (or schedule) | Unix timestamp in ms (integer). Past timestamps are accepted but logged. |
schedule | Alternative to cron/every/at | Natural-language string parsed by sol_nl_schedule. |
model | No | Model to use for the task. |
opts | No | Additional task options. Identity-bearing keys (user_uuid, permissions, listener, owner, task_id, container_id, plugin) are stripped from user input. |
delete_after_run | No | Auto-delete after execution. at jobs only — rejected for cron/every. |
Response (200)
{
"status": "ok",
"id": 42,
"next_run": 1716192000000
}
Error Responses
All error bodies speak the Zerg envelope — {"ok":false,"error":{"code":"…","message":"…"}} — where the table shows <code> inside error.code.
| Code | Body (error.code) | Condition |
|---|---|---|
| 400 | missing prompt | Empty prompt. |
| 400 | must specify at, every, or cron | None of the schedule keys provided. |
| 400 | at must be a positive integer (ms timestamp) | at not an integer. |
| 400 | every must be a positive integer (ms) | every not a positive integer. |
| 400 | invalid cron expression | cron failed sol_cron:parse/1. |
| 400 | delete_after_run only supported for 'at' jobs | delete_after_run: true on non-at schedule. |
| 400 | <create error> | sol_scheduler:create_job/1 returned an error. |
| 403 | insufficient_permissions | Non-admin caller (middleware, {admin, require} scope). |
| 429 | internal_error (see note) | Global cap max_scheduled_jobs (1000) or per-user quota max_scheduled_jobs_per_user (100) reached. |
429 note: the quota arms correctly answer 429 (capacity is never a 500), but the handler currently routes the quota reason through the generic error mapper, so the body carries the
internal_errorcode instead of a dedicated quota code. Dispatch on the status, not the code, on these arms. (Flagged for canonical-side repair.)
Get Job Detail
GET /api/v1/schedule/:id
Returns details for a single scheduled job. Admin-only — the job’s
prompt and opts are not disclosed to non-admin callers (403).
Response (200):
{
"id": 1,
"name": "Daily health check",
"schedule_type": "cron",
"cron_expr": "0 9 * * *",
"interval_ms": null,
"at_ms": null,
"next_run_ms": 1716192000000,
"last_run_ms": 1716105600000,
"status": "active",
"prompt": "Check system health and report any issues",
"model": "glm-5.1",
"opts": {},
"delete_after_run": false,
"consecutive_errors": 0,
"enabled": true,
"currently_running": false,
"tz": "UTC",
"anchor_ms": 1716000000000
}
anchor_msis included only when set (used to anchor drift-corrected intervals).tzis always"UTC"— all cron/at/every scheduling is naive UTC. All time fields use the_mssuffix (milliseconds).
Error Responses:
| Code | Body (error.code) | Condition |
|---|---|---|
| 400 | invalid id | :id not parseable as an integer. |
| 403 | forbidden | Non-admin caller. |
| 404 | job not found | Unknown id. |
Delete a Scheduled Job
DELETE /api/v1/schedule/:id
Cancel and remove a scheduled job. Admin-only.
Response (200):
{ "status": "deleted" }
Error Responses:
| Code | Body (error.code) | Condition |
|---|---|---|
| 400 | invalid id | :id not an integer. |
| 403 | forbidden | Non-admin. |
| 404 | job not found | Unknown id. |
| 409 | job currently running | Job is mid-execution. |
Pause a Job
POST /api/v1/schedule/:id/pause
Pause a scheduled job without deleting it. The job will not fire until
/unpause is called. Admin-only.
Response (200):
{ "status": "paused" }
Error Responses:
| Code | Body (error.code) | Condition |
|---|---|---|
| 400 | invalid id | :id not an integer. |
| 403 | forbidden | Non-admin. |
| 404 | job not found | Unknown id. |
Unpause a Job
POST /api/v1/schedule/:id/unpause
Resume a paused job. Admin-only.
Response (200):
{ "status": "active" }
Error Responses: same shape as pause (400 / 403 / 404), plus one
extra 400 arm: an unreachable schedule (no reachable fire time, e.g. an
impossible cron that survived an older create) is rejected at unpause time
and
the job stays disabled.
Trigger a Job Immediately
POST /api/v1/schedule/:id/run
Trigger immediate execution of a scheduled job, regardless of its schedule. Admin-only.
Response (200):
{ "status": "dispatched" }
Error Responses:
| Code | Body (error.code) | Condition |
|---|---|---|
| 400 | invalid id | :id not an integer. |
| 400 | job is disabled, unpause first | Job is currently paused. |
| 403 | forbidden | Non-admin. |
| 404 | job not found | Unknown id. |
| 409 | job already running | Job is mid-execution. |
Job Object Shape
Every job endpoint that returns a single job or a list of jobs uses the same
shape produced by sol_http_json:schedule_job_to_json/1:
| Field | Type | Description |
|---|---|---|
id | integer | Job id. |
name | string | Human-readable name. |
schedule_type | string | cron | every | at (atom stringified). |
cron_expr | string|null | Cron expression (only for cron). |
interval_ms | integer|null | Interval (only for every). |
at_ms | integer|null | Timestamp (only for at). |
next_run_ms | integer|null | Next scheduled run, ms. |
last_run_ms | integer|null | Last run, ms. |
status | string | active | paused (atom stringified). |
prompt | string | The prompt dispatched at fire time. |
model | string|null | Model override. |
opts | object | Task options. |
delete_after_run | boolean | Auto-delete after run (at only). |
consecutive_errors | integer | Error streak (auto-pause at 10). |
enabled | boolean | Whether the job is enabled. |
currently_running | boolean | Whether the job is mid-execution. |
tz | string | Always "UTC" — scheduling is naive UTC. |
anchor_ms | integer|omitted | Drift anchor (only when set). |
Missed-Job Detection
The scheduler detects jobs that missed their scheduled time during downtime. On startup:
- All stored jobs are loaded from ETS.
- Jobs with
next_run_msin the past are identified. - Up to 5 missed jobs are dispatched with a 5-second stagger.
- Jobs with 10+ consecutive errors are automatically paused.
This ensures tasks are not permanently lost after server restarts.
Limits
| Parameter | Default | Description |
|---|---|---|
max_scheduled_jobs | 1000 | Global maximum active jobs (429 on exceed) |
max_scheduled_jobs_per_user | 100 | Per-user quota of active jobs |
max_consecutive_errors | 10 | Auto-pause threshold |
max_catchup_runs | 5 | Missed jobs dispatched on startup |
catchup_stagger_ms | 5000 | Delay between catch-up dispatches |
timer_clamp_ms | 60000 | Maximum timer precision |
max_dispatch_per_tick | 5 | Jobs dispatched per scheduler tick |
Cron Expression Format
5-field cron expressions:
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, 0=Sunday)
│ │ │ │ │
* * * * *
| Expression | Meaning |
|---|---|
0 9 * * * | Every day at 09:00 |
*/5 * * * * | Every 5 minutes |
0 */2 * * * | Every 2 hours |
0 9 * * 1 | Every Monday at 09:00 |
0 0 1 * * | First of every month at midnight |
User Attribution
Each job records the user_uuid of the creating user (captured at creation time
from sol_identity:get_uuid/0). When the job fires, the task is dispatched with
this user_uuid, ensuring proper ownership of results. Permissions are also
captured at creation time and replayed at fire time.