Oban background jobs

This feature integrates Oban, Elixir's robust background job processing library, into your Phoenix application with complete setup automation. It handles all configuration, database migrations, and testing infrastructure needed to start processing background jobs immediately.

Key Benefits

  • Reliable job processing with database-backed persistence and automatic retries
  • Multiple queue support with configurable concurrency (default, mailers, high, low priority)
  • Built-in monitoring with job pruning and cron scheduling capabilities
  • Testing-ready with Oban.Testing integration for deterministic test behavior

Implementation Details The tool automatically installs the Oban dependency and configures four distinct queues with different concurrency levels. It integrates Oban into your application's supervision tree and sets up essential plugins including job pruning (24-hour retention) and cron scheduling. Database migrations are generated to create the required jobs table, while test environments are configured with manual testing mode to prevent job execution during tests.

Usage Example

defmodule MyApp.EmailWorker do
  use Oban.Worker, queue: :mailers, max_attempts: 3

  @impl Oban.Worker
  def perform(%Oban.Job{args: %{"user_id" => user_id}}) do
    user = MyApp.Accounts.get_user!(user_id)
    MyApp.Mailer.send_welcome_email(user)
    :ok
  end
end

# Enqueue jobs
%{user_id: 123}
|> MyApp.EmailWorker.new()
|> Oban.insert()

Configuration Queue concurrency is pre-configured with sensible defaults: 10 for default jobs, 20 for mailers, 50 for high priority, and 5 for low priority tasks. Cron scheduling is enabled but requires you to add specific job schedules to the crontab configuration as needed.