Cron jobs
Scheduled commands inside an app or database container, their runs and the master switch per target.
A job runs a command inside a running container on a cron schedule. Every job belongs to one target, an app or a database, and targetKind names which ("app" or "database"). Runs and their output are gated on manage_crons, not on view: stdout can carry whatever the command printed.
Reading
appCronJobs
Needs manage_crons. Returns CronJobsView.
An app's cron jobs, its master switch and its pickable services.
| Argument | Type | Description |
|---|---|---|
appId | ID! |
query {
appCronJobs(appId: "prj_9f1c2ab7d3e4f5a6") {
enabled
services
jobs {
id
name
schedule
}
}
}databaseCronJobs
Needs manage_crons. Returns CronJobsView.
A database's cron jobs and its master switch.
| Argument | Type | Description |
|---|---|---|
databaseId | ID! |
query {
databaseCronJobs(databaseId: "db_9f1c2ab7d3e4f5a6") {
enabled
services
jobs {
id
name
schedule
}
}
}cronRuns
Needs manage_crons. Returns [CronRun!].
One job's run history, newest first. Gated on manage_crons and not on view: stdout can carry whatever the command printed.
| Argument | Type | Description |
|---|---|---|
jobId | ID! | |
limit | Int |
query {
cronRuns(jobId: "cron_9f1c2ab7d3e4f5a6") {
id
status
exitCode
startedAt
}
}Jobs
createCronJob
Needs manage_crons. Returns CronJob.
Add a job to an app or a database. targetKind is app or database.
| Argument | Type | Description |
|---|---|---|
input | CronJobInput! | |
input.command | String | |
input.description | String | |
input.enabled | Boolean | |
input.env | [CronJobEnvInput!] | Replaces the job's variables wholesale when present. |
input.keepRuns | Int | 10 to 500. |
input.maxAttempts | Int | 1 to 4. 1 means no retry. |
input.name | String | |
input.overlap | String | skip | allow. |
input.schedule | String | 5-field cron. |
input.service | String | Empty => the target's own container. |
input.shell | String | sh | bash. |
input.timeoutSeconds | Int | Per attempt, 1s to 24h. |
input.timezone | String | IANA zone, e.g. Europe/Rome. |
input.user | String | |
input.workdir | String | |
targetId | ID! | |
targetKind | String! | app | database. |
mutation {
createCronJob(
targetKind: "app"
targetId: "prj_9f1c2ab7d3e4f5a6"
input: { name: "nightly-report", schedule: "0 3 * * *", command: "node scripts/report.js", timezone: "Europe/Rome" }
) {
id
name
nextRunAt
}
}updateCronJob
Needs manage_crons. Returns CronJob.
Edit a job. Every omitted field is left as it is.
| Argument | Type | Description |
|---|---|---|
id | ID! | |
input | CronJobInput! | |
input.command | String | |
input.description | String | |
input.enabled | Boolean | |
input.env | [CronJobEnvInput!] | Replaces the job's variables wholesale when present. |
input.keepRuns | Int | 10 to 500. |
input.maxAttempts | Int | 1 to 4. 1 means no retry. |
input.name | String | |
input.overlap | String | skip | allow. |
input.schedule | String | 5-field cron. |
input.service | String | Empty => the target's own container. |
input.shell | String | sh | bash. |
input.timeoutSeconds | Int | Per attempt, 1s to 24h. |
input.timezone | String | IANA zone, e.g. Europe/Rome. |
input.user | String | |
input.workdir | String |
mutation {
updateCronJob(
id: "cron_9f1c2ab7d3e4f5a6"
input: { name: "nightly-report", schedule: "0 3 * * *", command: "node scripts/report.js", timezone: "Europe/Rome" }
) {
id
name
schedule
enabled
nextRunAt
}
}deleteCronJob
Needs manage_crons. Returns Boolean.
Delete a job and its run history.
| Argument | Type | Description |
|---|---|---|
id | ID! |
mutation {
deleteCronJob(id: "cron_9f1c2ab7d3e4f5a6")
}setCronEnabled
Needs manage_crons. Returns Boolean.
Turn cron jobs on or off for one target. Off stops the schedule and keeps the jobs; runs already in flight are left to finish.
| Argument | Type | Description |
|---|---|---|
enabled | Boolean! | |
targetId | ID! | |
targetKind | String! | app | database. |
mutation {
setCronEnabled(targetKind: "app", targetId: "prj_9f1c2ab7d3e4f5a6", enabled: false)
}Runs
runCronJobNow
Needs manage_crons. Returns CronRun.
Run a job now, outside its schedule. Honours the overlap setting: while a run is in flight, a job set to skip answers with a skipped run.
| Argument | Type | Description |
|---|---|---|
id | ID! |
mutation {
runCronJobNow(id: "brun_9f1c2ab7d3e4f5a6") {
id
status
exitCode
startedAt
}
}cancelCronRun
Needs manage_crons. Returns Boolean.
Stop a run that is in flight.
| Argument | Type | Description |
|---|---|---|
id | ID! |
mutation {
cancelCronRun(id: "brun_9f1c2ab7d3e4f5a6")
}See also
Did this page help you?