guides/learning/defining_queues.md
Queues are the foundation of how Oban organizes and processes jobs. They allow you to:
Each queue operates independently with its own set of worker processes and concurrency limits.
Queues are defined as a keyword list where the key is the name of the queue and the value is the maximum number of concurrent jobs. The following configuration would start four queues with concurrency ranging from 5 to 50:
config :my_app, Oban,
queues: [default: 10, mailers: 20, events: 50, media: 5],
repo: MyApp.Repo
In this example:
default queue will process up to 10 jobs simultaneouslymailers queue will process up to 20 jobs simultaneouslyevents queue will process up to 50 jobs simultaneouslymedia queue will process up to 5 jobs simultaneouslyFor more control, you can use an expanded form to configure queues with individual overrides:
config :my_app, Oban,
queues: [
default: 10,
mailers: [limit: 20, dispatch_cooldown: 50],
events: [limit: 50, paused: true],
media: [limit: 1, global_limit: 10]
],
repo: MyApp.Repo
This expanded configuration demonstrates several advanced options:
mailers queue has a dispatch cooldown of 50ms between job fetchingevents queue starts in a paused state, which means it won't process anything until
Oban.resume_queue/2 is called to start itmedia queue uses a global limit (an Oban Pro feature)When a queue is configured with paused: true, it won't process any jobs until explicitly
started. Note that this pause will only affect the queue for the local node.
This is useful for:
You can resume a paused queue programmatically:
Oban.resume_queue(queue: :events)
And pause an active queue:
Oban.pause_queue(queue: :media)
There isn't a limit to the number of queues or how many jobs may execute concurrently in each queue. However, consider these important guidelines:
Each queue will run as many jobs as possible concurrently, up to the configured limit. Make sure your system has enough resources (such as database connections) to handle the concurrent load.
Consider the total concurrency across all queues. For example, if you have 4 queues with limits of 10, 20, 30, and 40, your system needs to handle up to 100 concurrent jobs, each potentially requiring database connections and other resources.
2 on three separate nodes is effectively a global limit of six
concurrent jobs. If you require a global limit, you must restrict the number of nodes running a
particular queue or consider Oban Pro's Smart Engine, which can manage global
concurrency automatically!Only jobs in the configured queues will execute. Jobs in any other queue will stay in the database untouched. Be sure to configure all queues you intend to use.
Organize queues by workload characteristics. For example:
Pay attention to the number of concurrent jobs making expensive system calls (such as calls to resource-intensive tools like FFMpeg or ImageMagick). The BEAM ensures that the system stays responsive under load, but those guarantees don't apply when using ports or shelling out commands.
Consider creating dedicated queues with lower concurrency for jobs that interact with external processes or services that have their own concurrency limitations.