GoodJob is a concurrent, Postgres-based job queue backend for Elixir.
GoodJob provides a complete job queue system with:
- PostgreSQL backend with advisory locks
- LISTEN/NOTIFY for low-latency job dispatch
- Cron-like scheduled jobs
- Batch job support
- Concurrency controls
- Retry mechanisms
Configuration
config :good_job,
repo: MyApp.Repo,
queues: "*",
max_processes: 5,
poll_interval: 10Usage
# Define a job
defmodule MyApp.MyJob do
use GoodJob.Job
def perform(%{data: data}) do
# Your job logic
end
end
# Enqueue a job
MyApp.MyJob.enqueue(%{data: "hello"})
Summary
Functions
Cleans up preserved job records older than the specified time.
Returns the current configuration.
Enqueues a job for execution.
Creates a new batch for grouping jobs together.
Pauses job execution for a given queue or job class.
Checks if job execution is paused for a given queue or job class.
Shuts down all GoodJob processes gracefully.
Checks if GoodJob is shut down.
Returns job statistics for all queues.
Returns job statistics for a specific queue.
Unpauses job execution for a given queue or job class.
Functions
Cleans up preserved job records older than the specified time.
Options
:older_than- Jobs older than this (in seconds) will be deleted. Default: 14 days:include_discarded- Whether to include discarded jobs. Default: configcleanup_discarded_jobs(true):max_count- Maximum number of preserved jobs/executions to keep. Default: configcleanup_preserved_jobs_max_count(nil)
Returns the current configuration.
Enqueues a job for execution.
Examples
GoodJob.enqueue(MyApp.MyJob, %{data: "hello"})
GoodJob.enqueue(MyApp.MyJob, %{data: "hello"}, queue: "high_priority", priority: 1)
# With concurrency control (limits from module or opts; see :concurrency_config)
GoodJob.enqueue(MyApp.MyJob, %{data: "hello"}, concurrency_key: "user_123", concurrency_config: [total_limit: 5])
# Execute inline (synchronously)
GoodJob.enqueue(MyApp.MyJob, %{data: "hello"}, execution_mode: :inline)
# Bulk enqueue (single NOTIFY): used by `GoodJob.Batch.enqueue_all/1`
GoodJob.enqueue(MyApp.MyJob, %{data: "hello"}, batch_id: batch_id, listen_notify: false)
Creates a new batch for grouping jobs together.
Pauses job execution for a given queue or job class.
Options
:queue- Queue name to pause:job_class- Job class name to pause
Checks if job execution is paused for a given queue or job class.
Options
:queue- Queue name to check:job_class- Job class name to check
Shuts down all GoodJob processes gracefully.
Options
:timeout- Timeout in milliseconds to wait for shutdown. Default:-1(wait forever)
Checks if GoodJob is shut down.
@spec stats() :: map()
Returns job statistics for all queues.
Returns job statistics for a specific queue.
Unpauses job execution for a given queue or job class.
Options
:queue- Queue name to unpause:job_class- Job class name to unpause