Skip to content

How-to guides

How to run a cron job in the cloud

Give a scheduler a cron expression, a time zone and a command, and it starts the command on a machine at each time.

Updated · Facts checked · By Runtime Cloud

4 min read

Read as Markdown

That machine can be one you keep running, a CI service's scheduled workflow, or a managed scheduler that starts a fresh machine for each run. They differ in three ways that matter more than the syntax. A run can fail with nobody watching. A run can still be going when the next time comes. And daylight saving time can move your job by an hour.

On Runtime (withruntime.com), a job starts a fresh Linux machine at each time of its cron expression, in the time zone you name. It runs your command, keeps the exit code and output, and bills only while the command runs. Nothing stays up between runs. Each run is a new machine, so one run's files and processes never reach the next.

Where a cron job can run

Where it runs What you keep running What a missed or failed run does
crontab on a server you run The server, all month, and its updates Nothing tells you. Output goes to local mail or is lost
A CI service's scheduled workflow Nothing, but the repository must stay active GitHub may delay a scheduled run under load, and disables schedules in an idle public repository after 60 days
A managed scheduler with machines Nothing The run's state, exit code and output are kept, and a failed run can be retried

crontab is the right tool when the job must touch that one server's own disk. For anything else, a server that waits all day for a two-minute job is a cost and a machine to patch.

Schedule a job on Runtime

The schedule below runs at 06:30 London time on weekdays. The command runs without a shell unless you give it one, so it starts with bash -lc.

TypeScriptimport { Runtime } from "withruntime";const runtime = new Runtime();const job = await runtime.jobs.create({  name: `daily-report-${Date.now()}`,  schedule: { cron: "30 6 * * 1-5", timezone: "Europe/London" }, // 06:30 London time, weekdays  command: ["bash", "-lc", "date -u +%FT%TZ && echo report sent"],  timeoutSeconds: 600,  retry: { maxAttempts: 3, backoffSeconds: 60 },});try {  console.log(job.state, new Date(job.nextRunAt!).toISOString()); // active, the next weekday 06:30 London  await runtime.jobs.trigger(job.id); // one run now, besides the schedule  let run;  for (let i = 0; i < 240 && !run?.endedAt; i++) {    await new Promise((r) => setTimeout(r, 500));    [run] = (await runtime.jobs.runs(job.id, { limit: 1, order: "newest" })).data;  }  const logs = await runtime.jobs.logs(run!.id);  console.log(run!.state, run!.exitCode, JSON.stringify(logs).includes("report sent")); // succeeded 0 true  if (run!.exitCode !== 0) throw new Error(JSON.stringify(run));} finally {  await runtime.jobs.cancel(job.id);}

The same job from the command line:

Terminalruntime jobs create daily-report --cron "30 6 * * 1-5" --timezone Europe/London \  --attempts 3 --backoff 60 -- bash -lc 'date -u +%FT%TZ && echo report sent'runtime jobs trigger <jobId>     # one run now; the schedule does not moveruntime jobs logs <jobId> -f     # the latest run's outputruntime jobs cancel <jobId>      # end it for good

trigger is how to test a job before its first time comes. Delete the cancel line, and the job keeps its schedule.

Settings that decide whether it works

Setting What it does on Runtime
timezone An IANA name such as Europe/London. The job stays at 06:30 local time through daylight saving. UTC when omitted
retry maxAttempts from 1 to 5, the first attempt included, with backoffSeconds between attempts
timeoutSeconds How long one run may take before it is stopped. 30 minutes when omitted
Overlap Runs of one job never overlap. A time that comes while a run is still going is not started beside it
Output Each run keeps its exit code and its last 256 KiB of output

Mistakes to avoid

  • Writing the schedule in UTC for a local-time task. A job meant for 07:00 in New York runs at 06:00 or 07:00 local time depending on the season. Name the time zone instead of converting by hand.
  • A job that is not safe to run twice. A retry runs the command again from the start. Make the command check whether its work is already done, such as a file or row for today, before it writes anything.
  • Trusting */7 to mean every seven minutes. A step counts from the start of its field, so */7 in the minute field runs at :00, :07 and so on to :56, then at :00 again, four minutes later. See cron expressions.
  • No owner for failures. Read the run's state each morning, or have the command post to a chat or a webhook when it fails.

Sources

Facts on this page were checked on 17 November 2026.

Cut your cloud billby 66%.

7 days of Pro for $0, and no card to sign up. Billed by the second after.

Start your free trial