Background jobs
How jobs are queued and run, the scheduler, and the jobs core runs on its own.
Jobs run on Oban, with its tables in the platform schema. Any node inserts jobs. Only nodes with CARDINAL_ROLE worker or all, and cardinal start in dev, execute them.
A job's life
Code calls Cardinal.Jobs.enqueue/4 inside its transaction. The job row carries the site, the user and the request id.
The transaction commits, and the job becomes visible. A rollback leaves no job.
A worker node picks the job up. CardinalJobs.Worker restores the user's Ctx and runs perform(ctx, args) in the site's transaction.
A raise writes an Error Log and Oban retries the job. Jobs of disabled users and inactive sites are cancelled. Jobs wait while a site is in maintenance.
A job left executing by a dead node becomes available again after 35 minutes, or CARDINAL_JOB_RESCUE_AFTER seconds.
Cardinal.Jobs.enqueue(ctx, MyApp.Workers.SyncWorker, %{"customer" => "CUST-0001"})Queues
| Queue | Workers at once per node | Used for |
|---|---|---|
short | 4 | Scheduler ticks and automation steps |
default | 2 | Webhooks, Web Push, SMS, Telegram, and jobs that name no queue |
long | 1 | Imports, prepared reports, bulk PDFs, search rebuilds, daily sweeps |
mail | 5 | Sending and receiving mail |
apps | 5 | Apps' own workers |
Scheduler
Every minute, Oban's cron runs SchedulerTickWorker on one leader node.
It inserts one TenantTickWorker job per active site.
Each site's tick enqueues its due Scheduled Job Types in the site's time zone, and runs due Schedule and Date Offset automations.
After downtime, each scheduled job runs once to catch up. Missed runs are not backfilled. cardinal scheduler pause, disable and status control it per site.
Jobs core runs on its own
| Worker | Runs | Does |
|---|---|---|
AuthSweepWorker | Daily | Deletes expired sessions, auth tokens and rate counters |
ObjectSweepWorker | Daily | Deletes stored objects no File has named for 24 hours |
LogRetentionWorker | Daily | Prunes logs per Log Settings, 5,000 rows a transaction |
UserInvitationExpiryWorker | Daily | Expires Pending invitations older than 3 days |
NotificationDailyWorker | Daily | Days Before and Days After Notification rules |
AutoRepeatDailyWorker | Daily | Queues each Auto Repeat due today |
EmailFlushWorker | Every minute | Resets stuck mail and queues due mail |
EmailReceiveWorker | Every minute | Polls each Email Account with incoming mail on |
Jobs other code queues
| Worker | One job is |
|---|---|
EmailSendWorker | One Email Queue row's delivery |
PasswordResetWorker | One forgot-password request |
BulkWorker | A list's bulk delete, edit, submit, cancel or assign |
BulkPdfWorker | One PDF of many Records |
DataImportWorker | One Data Import run |
PreparedReportWorker | One Prepared Report run |
SearchIndexWorker | One RecType's global search rows rebuilt |
WebhookWorker | One webhook call, 3 attempts, logged |
AutomationStepWorker | One step of an Automation Run, 5 attempts |
PushWorker, SmsSendWorker, TelegramWorker | One Web Push, SMS batch or Telegram message |
RoleProfileSyncWorker, ModuleProfileSyncWorker | Applies a changed profile to its users |
AutoRepeatWorker | One Auto Repeat copy |
Long workers commit in steps and record their progress on the job row, so a retry after a kill starts at the first item not yet committed.
From the CLI, see cardinal jobs in the CLI reference. For app workers, see Build.