Jobs
A job runs its command on a schedule: each run boots a fresh machine, runs run to its end, and is billed for that time alone. POST /v2/jobs takes a JobCreate:
| Field | What it sets |
|---|---|
schedule |
When it runs. A cron line with cron and timezone, or one time with at. |
run |
The command each run runs; the run ends when it ends. |
retry |
How a failed run is run again; never when omitted. |
secrets |
Which of its org's secrets each run gets; every one whose scope admits it when omitted. |
maxCost |
The most one run may cost, in US dollars ("0.50"): a run pauses once it has cost that, as a machine at its maxCost does. |
Schedule a job and run it now#
TypeScriptimport { Runtime } from "withruntime";const runtime = new Runtime();const job = await runtime.jobs.create({ name: `nightly-${Date.now()}`, schedule: { cron: "0 3 * * *", timezone: "America/Denver" }, run: { cmd: ["python3", "-c", "print(sum([125, 250, 375]))"] },});try { await job.run(); let run; for (let i = 0; i < 240 && !run?.endedAt; i++) { await new Promise((r) => setTimeout(r, 250)); for await (const each of runtime.jobRuns.list({ job: job.id })) run = each; } const output = await runtime.jobRuns.output(run!.id); console.log(run!.exitCode, JSON.stringify(output).slice(0, 200)); // 0 ... 750 if (run!.exitCode !== 0) throw new Error(JSON.stringify(run));} finally { await job.delete();}POST /v2/jobs/{id}:pause stops its schedule and POST /v2/jobs/{id}:resume starts it again. GET /v2/job-runs lists every run of a job.
Next steps#
Give this to your agent#
Paste this into your coding agent:
Read https://withruntime.com/docs/jobs.md. Turn this project's scheduled task into a Runtime job: create it with its cron schedule, timezone and command, run it once now, and print that run's exit code and output.
This page as Markdown: https://withruntime.com/docs/jobs.md
Try it on your own work.Signing up takes no card. Your first sandbox asks for one, and the trial starts then. Or paste the setup prompt into your agent.