PhoenixKit.ScheduledJobs.Workers.ProcessScheduledJobsWorker (phoenix_kit v1.7.71)

Copy Markdown View Source

Oban worker that processes pending scheduled jobs.

This worker runs every minute via Oban's cron plugin and processes all scheduled jobs that are due for execution. It replaces the single-purpose PublishScheduledPostsJob with a universal job processor.

Configuration

Add to your Oban cron configuration:

config :your_app, Oban,
  plugins: [
    {Oban.Plugins.Cron,
     crontab: [
       {"* * * * *", PhoenixKit.ScheduledJobs.Workers.ProcessScheduledJobsWorker}
     ]}
  ]

Behavior

  1. Runs every minute
  2. Queries all pending jobs where scheduled_at <= now
  3. Orders by priority (DESC) then scheduled_at (ASC)
  4. For each job, loads the handler module and calls execute/2
  5. Marks jobs as executed or failed based on result
  6. Logs summary of processed jobs

Error Handling

  • Jobs that fail are marked with incremented attempt count
  • After max_attempts, job status changes to "failed"
  • Exceptions are caught, logged, and treated as failures
  • Worker itself always returns :ok to prevent Oban retries