Tearleads

job_runs API Postgres table

One invocation of a scheduled job: a Cron trigger and the steps it ran.

Declared in packages/api-shared/src/schema/jobRuns.ts

Description

Jobs and their schedules are defined in the API's code (src/jobs/catalog.ts) and in wrangler.jsonc, not here; a row records only what one invocation did. The row is inserted as running before the first step and updated once every step has finished, so an invocation the platform cut off still leaves a row behind. Recording never stops a job from running: a run whose row cannot be written still runs, unrecorded. The hourly storage job prunes old rows (job_runs_started_at_idx).

Indexes:

  • job_runs_job_started_at_id_idx backs a job's newest-first history and its latest run.
  • job_runs_job_status_started_at_idx backs a job's history filtered to one status and its latest success or failure.
  • job_runs_started_at_idx backs retention.

Columns

  • iduuid
    • primary key
    • not null
    • default gen_random_uuid()

    Run id. The root console reads one run by it and pages a job's history newest first by (startedAt, id).

  • job_idtext
    • not null

    The catalog id of the job, such as billing-maintenance.

  • statustext
    • not null

    running, succeeded, or failed (see JobRunStatus).

  • scheduled_attimestamp
    • not null

    The Cron time the platform invoked the run for.

  • started_attimestamp
    • not null

    When the run started and ended; finishedAt is null while it runs, or when it never ended.

  • finished_attimestamp
    • nullable

    When the run started and ended; finishedAt is null while it runs, or when it never ended.

  • stepsjsonb
    • not null
    • default '[]'::jsonb

    Each step's status, duration, counts, and error, in run order.

  • outputjsonb
    • nullable

    Console lines the steps wrote, capped per run.

  • errortext
    • nullable

    Why the run failed, when it did.

Indexes

  • job_runs_job_started_at_id_idx(job_id, started_at, id)
    • job_runs_job_status_started_at_idx(job_id, status, started_at)
      • job_runs_started_at_idx(started_at)