on this page

TutorialsRun a cron job without a server

Run a cron job without a server

A scheduled job that checks a list of websites every five minutes, records each status code and response time in SQLite, and serves the results on a page. Once a night it deletes the old rows. Nothing to keep running: the platform calls your code on the schedule.

It takes about fifteen minutes. If you haven't installed the CLI yet, do steps 1 and 2 of the quick start first (ribo install and ribo login).


How scheduling works here

You write the schedule in ribo.toml as a cron expression, and export a pulse function next to the usual fetch. At each slot the platform calls pulse(event, env) with the same bindings fetch gets. Schedules are 5-field cron and always UTC. The shortest interval is one minute, and a pulse fires within about 30 seconds of its slot.

A pulse that fails is not retried; the next slot fires as normal. For a checker that runs every five minutes, a missed run is a gap in the table and nothing more.


1. Create the database

mkdir site-checker && cd site-checker
ribo db create checks

2. Write the config

ribo.toml

[cell]
name = "site-checker"
js   = "./cell.js"

[[bindings]]
type     = "c3"
binding  = "DB"
database = "checks"

# Comma-separated list of URLs to check.
[[bindings]]
type    = "text"
binding = "TARGETS"
value   = "https://tissue.systems,https://docs.tissue.systems"

# Every five minutes: check each target.
[[pulse]]
schedule = "*/5 * * * *"

# 03:00 UTC every day: delete rows older than seven days.
[[pulse]]
schedule = "0 3 * * *"

Put your own URLs in value. A text binding is a plain string in the config, which is fine for a list like this; anything secret belongs in a vault binding instead.


3. Write the Cell

cell.js

const SCHEMA = `
  CREATE TABLE IF NOT EXISTS checks (
    id         INTEGER PRIMARY KEY AUTOINCREMENT,
    url        TEXT    NOT NULL,
    status     INTEGER,
    ms         INTEGER NOT NULL,
    error      TEXT,
    checked_at TEXT    NOT NULL
  );
  CREATE INDEX IF NOT EXISTS checks_url_time ON checks (url, checked_at);
`;

export default {
  async pulse(event, env) {
    await env.DB.exec(SCHEMA);

    if (event.cron === "0 3 * * *") {
      await env.DB.prepare(
        "DELETE FROM checks WHERE checked_at < datetime('now', '-7 days')"
      ).run();
      return;
    }

    const targets = env.TARGETS.split(",").map((s) => s.trim()).filter(Boolean);
    const results = await Promise.all(targets.map(check));

    // One batch is one transaction: every row from this run lands, or none does.
    await env.DB.batch(
      results.map((r) =>
        env.DB.prepare(
          "INSERT INTO checks (url, status, ms, error, checked_at) VALUES (?, ?, ?, ?, datetime(?))"
        ).bind(r.url, r.status, r.ms, r.error, event.scheduledTime.toISOString())
      )
    );
  },

  async fetch(request, env) {
    await env.DB.exec(SCHEMA);
    const { results } = await env.DB.prepare(`
      SELECT url, status, ms, error, checked_at
      FROM checks
      WHERE checked_at > datetime('now', '-1 day')
      ORDER BY checked_at DESC
      LIMIT 200
    `).all();

    if (new URL(request.url).pathname === "/json") {
      return Response.json(results);
    }
    return new Response(page(results), {
      headers: { "content-type": "text/html; charset=utf-8" },
    });
  },
};

async function check(url) {
  const started = Date.now();
  try {
    const res = await fetch(url, {
      redirect: "manual",
      signal: AbortSignal.timeout(10000),
    });
    return { url, status: res.status, ms: Date.now() - started, error: null };
  } catch (err) {
    return { url, status: null, ms: Date.now() - started, error: err.name };
  }
}

function page(rows) {
  const body = rows.map((r) => `
    <tr>
      <td>${esc(r.checked_at)}</td>
      <td>${esc(r.url)}</td>
      <td>${r.status ?? esc(r.error)}</td>
      <td>${r.ms} ms</td>
    </tr>`).join("");
  return `<!doctype html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Site checks</title>
<style>
  body { font: 15px/1.5 system-ui, sans-serif; margin: 2rem; }
  table { border-collapse: collapse; }
  td, th { padding: 4px 12px; border-bottom: 1px solid #ddd; text-align: left; }
</style>
<h1>Site checks, last 24 hours</h1>
<table>
  <tr><th>Checked (UTC)</th><th>URL</th><th>Status</th><th>Time</th></tr>
  ${body || '<tr><td colspan="4">No checks yet. The first one runs at the next five-minute mark.</td></tr>'}
</table>`;
}

function esc(s) {
  return String(s ?? "").replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);
}

Some details that matter:

  • event.cron is the expression that fired, exactly as written in ribo.toml, which is how one pulse function tells the nightly cleanup from the five-minute check.
  • event.scheduledTime is a Date. The insert passes it through SQLite's datetime(), which stores it as 2026-12-02 17:05:00, the same shape datetime('now', '-7 days') produces. Text columns compare as strings, so both sides of a comparison need the same format.
  • redirect: "manual" records a redirect as its own status (301, 302) rather than following it. Drop that line if you'd rather see the status of the final page.
  • Time spent waiting on fetch() doesn't count against the Cell's CPU limit, so slow sites only cost wall-clock time. AbortSignal.timeout(10000) gives up on a site after 10 seconds and records TimeoutError.

4. Deploy

ribo deploy
deployed  site-checker
address   33ed412f2h8wd
kind      js
url       https://site-checker.strand-9c.tissue.dev
c3        DB→checks
text      TARGETS
pulse     */5 * * * *, 0 3 * * *

The pulse line lists the schedules the platform registered. A schedule it can't parse fails the deploy with a 400 that names the expression, and nothing is published.


5. Watch it run

Wait for the next five-minute mark, then open the url in a browser. Each run adds one row per target. The same data is at /json:

curl -s https://site-checker.strand-9c.tissue.dev/json
[{"url":"https://tissue.systems","status":200,"ms":84,"error":null,"checked_at":"2026-12-02 17:05:00"}]

From the terminal you can query the table directly:

ribo db exec checks "SELECT url, count(*), avg(ms) FROM checks GROUP BY url"

What you have

A cron job running in the cloud with no server or process of yours: every five minutes it checks your sites, keeps a week of history in SQLite, and shows the last day on a public page. To change what it checks, edit value in ribo.toml and run ribo deploy. To change when, edit the schedule lines; */5 becomes */15 for every quarter hour, and 0 9 * * 2-6 is 09:00 UTC on weekdays.

Day-of-week in these schedules counts from 1 for Sunday, so Monday is 2. The pulse overview has the full field table.


Next steps