Packages
oban
0.1.0
2.23.0
2.22.1
2.22.0
2.21.1
2.21.0
2.20.3
2.20.2
2.20.1
2.20.0
2.19.4
2.19.3
2.19.2
2.19.1
2.19.0
2.18.3
2.18.2
2.18.1
2.18.0
2.17.12
2.17.11
2.17.10
2.17.9
2.17.8
2.17.7
2.17.6
2.17.5
2.17.4
2.17.3
2.17.2
2.17.1
2.17.0
2.16.3
2.16.2
2.16.1
2.16.0
2.15.4
2.15.3
2.15.2
2.15.1
2.15.0
2.14.2
2.14.1
2.14.0
2.13.6
2.13.5
2.13.4
2.13.3
2.13.2
2.13.1
2.13.0
2.12.1
2.12.0
2.11.3
2.11.2
2.11.1
2.11.0
2.10.1
2.10.0
retired
2.9.2
2.9.1
2.9.0
2.8.0
2.7.2
2.7.1
2.7.0
2.6.1
2.6.0
2.5.0
2.4.3
2.4.2
2.4.1
2.4.0
2.3.4
2.3.3
2.3.2
2.3.1
2.3.0
2.2.0
2.1.0
2.0.0
2.0.0-rc.3
2.0.0-rc.2
2.0.0-rc.1
2.0.0-rc.0
1.2.0
1.1.0
1.0.0
1.0.0-rc.2
1.0.0-rc.1
0.12.1
0.12.0
0.11.1
0.11.0
0.10.1
0.10.0
0.9.0
0.8.1
0.8.0
0.7.1
0.7.0
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0
0.1.0
Robust job processing, backed by modern PostgreSQL, SQLite3, and MySQL.
Current section
Files
Jump to
Current section
Files
lib/oban.ex
defmodule Oban do
@moduledoc """
This is a stub. New documentation will be added below, but this module isn't properly
documented.
## Pruning Historic Jobs
Job stats and queue introspection is built on keeping job rows in the database after they have
completed. This allows administrators to review completed jobs and build informative aggregates,
but at the expense of storage and an unbounded table size. To prevent the `oban_jobs` table from
growing indefinitely, Oban provides active pruning of `completed` jobs.
By default, pruning is disabled. To enable pruning we configure a supervision tree with the
`:prune` option. There are three distinct modes of pruning:
* `:disabled` - This is the default, where no pruning happens at all
* `{:maxlen, count}` - Pruning is based on the number of rows in the table, any rows beyond
the configured `count` will be deleted
* `{:maxage, seconds}` - Pruning is based on a row's age, any rows older than the configured
number of `seconds` will be deleted. The age unit is always specified in seconds, but values
on the scale of days, weeks or months are perfectly acceptable.
Pruning is best-effort and performed out-of-band. This means that all limits are soft; jobs
beyond a specified length or age may not be pruned immediately after jobs complete. Prune timing
is based on the configured `poll_interval`, where pruning occurs once for every 60 queue polls.
With the default `poll_interval` of 1 second that means pruning occurs at system startup and
then once every minute afterwards.
Note, only jobs in a `completed` or `discarded` state will be deleted. Currently `executing`
jobs and older jobs that are still in the `available` state will be retained.
"""
use Supervisor
alias Oban.{Config, Pruner}
alias Oban.Queue.Supervisor, as: QueueSupervisor
@type supervisor_option ::
{:name, module()}
| {:node, binary()}
| {:queues, [{atom(), pos_integer()}]}
| {:repo, module()}
@doc """
Starts an `Oban` supervision tree linked to the current process.
## Options
* `:name` — used for name supervisor registration
* `:node` — used to identify the node that the supervision tree is running in. If no value is
provided it will use the `node` name in a distributed system, the `hostname` in an isolated
node. See the "Node Name"
* `:repo` — specifies the Ecto repo used to insert and retreive jobs.
* `:queues` — a keyword list where the keys are queue names and the values are the concurrency
setting. For example, setting queues to `[default: 10, exports: 5]` would start the queues
`default` and `exports` with a combined concurrency level of 20. The concurrency setting
specifies how many jobs _each queue_ will run concurrently.
* `:poll_interval` - the amount of time between a queue pulling new jobs, specified in
milliseconds. This is directly tied to the resolution of scheduled jobs. For example, with a
`poll_interval` of 5_000ms scheduled jobs would be checked every 5 seconds. The default is
`1_000`, or 1 second.
* `:prune` - configures job pruning behavior, see "Pruning Historic Jobs" for more information
* `:shutdown_grace_period` - the amount of time a queue will wait for executing jobs to complete
before hard shutdown, specified in milliseconds. The default is `15_000`, or 15 seconds.
Note that any options passed to `start_link` will override options set through the `using` macro.
## Examples
To start an `Oban` supervisor within an application's supervision tree:
def start(_type, _args) do
children = [MyApp.Repo, {Oban, queues: [default: 50]}]
Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
end
## Node Name
When the `node` value hasn't been configured it will be generated based on the environment:
* In a distributed system the node name is used
* In a Heroku environment the system environment's `DYNO` value is used
* Otherwise, the system hostname is used
"""
@spec start_link([supervisor_option()]) :: Supervisor.on_start()
def start_link(opts) when is_list(opts) do
conf = Config.new(opts)
Supervisor.start_link(__MODULE__, conf, name: conf.name)
end
@impl Supervisor
def init(%Config{queues: queues} = conf) do
children = [prune_spec(conf) | Enum.map(queues, &queue_spec(&1, conf))]
Supervisor.init(children, strategy: :one_for_one)
end
defp prune_spec(conf) do
name = Module.concat([conf.name, "Pruner"])
{Pruner, conf: conf, name: name}
end
defp queue_spec({queue, limit}, conf) do
queue = to_string(queue)
name = Module.concat([conf.name, "Queue", String.capitalize(queue)])
opts = [conf: conf, queue: queue, limit: limit, name: name]
Supervisor.child_spec({QueueSupervisor, opts}, id: name)
end
end