cardinal

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

QueueWorkers at once per nodeUsed for
short4Scheduler ticks and automation steps
default2Webhooks, Web Push, SMS, Telegram, and jobs that name no queue
long1Imports, prepared reports, bulk PDFs, search rebuilds, daily sweeps
mail5Sending and receiving mail
apps5Apps' 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

WorkerRunsDoes
AuthSweepWorkerDailyDeletes expired sessions, auth tokens and rate counters
ObjectSweepWorkerDailyDeletes stored objects no File has named for 24 hours
LogRetentionWorkerDailyPrunes logs per Log Settings, 5,000 rows a transaction
UserInvitationExpiryWorkerDailyExpires Pending invitations older than 3 days
NotificationDailyWorkerDailyDays Before and Days After Notification rules
AutoRepeatDailyWorkerDailyQueues each Auto Repeat due today
EmailFlushWorkerEvery minuteResets stuck mail and queues due mail
EmailReceiveWorkerEvery minutePolls each Email Account with incoming mail on

Jobs other code queues

WorkerOne job is
EmailSendWorkerOne Email Queue row's delivery
PasswordResetWorkerOne forgot-password request
BulkWorkerA list's bulk delete, edit, submit, cancel or assign
BulkPdfWorkerOne PDF of many Records
DataImportWorkerOne Data Import run
PreparedReportWorkerOne Prepared Report run
SearchIndexWorkerOne RecType's global search rows rebuilt
WebhookWorkerOne webhook call, 3 attempts, logged
AutomationStepWorkerOne step of an Automation Run, 5 attempts
PushWorker, SmsSendWorker, TelegramWorkerOne Web Push, SMS batch or Telegram message
RoleProfileSyncWorker, ModuleProfileSyncWorkerApplies a changed profile to its users
AutoRepeatWorkerOne 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.

On this page