Docs
Live demo

Background operations

How Principal runs long operations as background jobs: lifecycle, retries, restarts, retention, live updates and locking.

On this page

Lifecycle#

QueuedRequest accepted, waiting for a worker.
RunningWorker runs steps and reports progress.
RetryingTransient failure, waiting to try again.
WaitingNeeds a decision from a person.
FinishedSucceeded, partly succeeded, failed or cancelled.

Every job uses these states, four results and one error and reason shape.

Behavior How and why it works
Retries
Transient errors (timeout, lost connection) retry after backoff, a limited number of times.
Decisions
Destructive choices wait as Needs decision (such as dropping or reassigning tables owned by a PostgreSQL role, except at TTL expiry). See Finish a waiting operation.
Pauses
Repeated discovery or drift failures pause runs on that target so broken links do not fill the queue. A passing connection check and one run end the pause (paused checks).
Locking
Target changes serialize under a target lock. Duplicate runs return 409 policy.apply_in_progress (apply) or 409 operation.already_running (discovery, drift, sync) with the active job.

Restarts and crashes#

Event Effect on running jobs
Graceful stop
Pod stops taking new jobs and waits JOBS_SHUTDOWN_TIMEOUT. Repeatable jobs re-queue with their target lock and no retry penalty.
Pod crash
Missing heartbeats for ~2.5 minutes mark jobs abandoned. Repeatable jobs (cleanups) restart. Others time out.
Single-attempt jobs
One-attempt jobs (drift fixes) fail after any stop.

Retention#

Nightly cleanup removes a job, its attempts and its stage log together.

Origin Default Setting (1–3650 days)
Person-started (direct or triggered)
180 days
JOBS_RETENTION_PERSON_DAYS
Scheduled or service
14 days
JOBS_RETENTION_SERVICE_DAYS

JOBS_CLEANUP_RETENTION governs only cleanup schedule runs. Cleanup retains any job still needed by:

  • An active or unfinished apply, template upgrade, bulk operation or sync approval (plus applies an upgrade waits on).
  • A waiting or failed deletion (Retry cleanup), failed notification (Resend) or newest credential delivery (Needs attention).
  • The last apply of a future-object rule, a cancelled bulk row or a kept child job.

Live updates and tracking#

Swipe the screenshot sideways to see all of it, or tap it to open it full size.

The activity bell groups operations into Now, Needs action and Recent.
  • Tracking. Watch jobs in the activity bell, Activity, GET /admin/jobs and GET /admin/jobs/{id}. Needs attention (GET /attention) lists work Principal stopped retrying: failed deliveries, paused targets and overdue TTL removals.
  • SSE stream. GET /events reads a shared database table, so worker pods update browsers on any copy.
  • Targeted refreshes. job.completed and job.failed include changed_reads (API paths to reread, empty for maintenance) and changed_objects (IDs for single-person applies, filtered by subscriber permissions like identities:read).
  • Replay. Direct edits arrive via audit events. The bell updates at most every 30s and pages refresh every 5 minutes. Reconnects replay up to 1 hour (SSE_EVENT_LOG_RETENTION_SECONDS), then reload (Resources shows a Refresh notice).
↑ ↓ to moveEnter to openEsc to close