Application.put_env(:sample, Sample.Repo, database: "oban_dev")
Application.put_env(:phoenix, :json_library, Jason)
Application.put_env(:sample, Sample.Endpoint,
http: [ip: {127, 0, 0, 1}, port: 5001],
server: true,
| defmodule QueueBreaker do | |
| @moduledoc """ | |
| Automatic queue pausing/resuming based on accumulated errors. | |
| ## Example | |
| Pause after 1000 errors: | |
| QueueBreaker.attach("risky-queue", 1000) | |
| """ |
Worker hooks are called after a job finishes executing. They can be defined as callback functions on the worker, or in a separate module for reuse across workers.
Hooks are called synchronously, from within the job's process with safety applied. Any exceptions or crashes are caught and logged, they won't cause the job to fail or the queue to crash.
Hooks do not modify the job or execution results. Think of them as a convenient alternative
| defmodule Metrics do | |
| @moduledoc false | |
| def attach(event) do | |
| counter = :counters.new(4, []) | |
| :persistent_term.put(event, counter) | |
| for idx <- 1..4, do: :counters.put(counter, idx, 0) |
| def start_supervised_oban!(opts) do | |
| opts = | |
| opts | |
| |> Keyword.put_new(:name, Oban) | |
| |> Keyword.put_new(:repo, MyApp.Repo) | |
| |> Keyword.put_new(:poll_interval, :timer.minutes(10)) | |
| |> Keyword.put_new(:shutdown_grace_period, 25) | |
| pid = start_supervised!({Oban, opts}, id: opts[:name]) |
| defmodule MyApp.TenantWorker do | |
| @moduledoc false | |
| use Oban.Worker | |
| @impl Worker | |
| def perform(%Job{conf: conf, args: %{"tenant" => tenant, "id" => id}}) do | |
| time = | |
| Time.utc_now() | |
| |> Time.truncate(:second) |
| alias Oban.Pro.Plugins.Relay | |
| Oban.Pro.Repo.start_link() | |
| Oban.start_link( | |
| repo: Oban.Pro.Repo, | |
| queues: [alpha: 2], | |
| plugins: [Oban.Pro.Plugins.Relay] | |
| ) |
| Oban.Pro.Repo.start_link() | |
| Oban.start_link( | |
| repo: Oban.Pro.Repo, | |
| queues: [alpha: 20], | |
| plugins: [Oban.Pro.Plugins.ChunkManager] | |
| ) | |
| :persistent_term.put(:chunk_bench_pid, self()) |
🌟 This worker is available through Oban.Pro
Workflow workers compose together with arbitrary dependencies between jobs,
allowing sequential, fan-out and fan-in execution workflows. Workflows are fault
tolerant, can be homogeneous or heterogeneous, and scale horizontally across all
available nodes. Workflows are unique to Oban—only possible due to historic job
retention.