Oban
Robust job processing in Elixir, backed by modern PostgreSQLFeatures
Scheduled Jobs - at any time in future down to second
CRON Jobs - Perodic jobs
Queue Control - start, stop, scale independently
Unique Jobs, Priority
See the Oban.Worker docs for more details on failure conditions and Oban.Telemetry for details on job reporting.
Usage
Defining Workers
Must define perform/1 function with %Oban.Job{} struct
args will always have string keys cuz serialization
Successful jobs return
:okor{:ok, value}to treat as success, return other for failure, discard, deferred
defmodule MyApp.Business do
use Oban.Worker,
queue: :events,
priority: 3,
max_attempts: 3,
tags: ["business"],
unique: [period: 30] #in seconds
@impl Oban.Worker
def perform(%Oban.Job{args: %{"id" => id} = args}) do
#work hard grrrrr
:ok
end
endEnqueueing Jobs
Jobs are enqueued by inserting Ecto struct into db. All workers define a new/2 function that serves as changest.
At specific future time
Periodic Jobs
Has one minute resolution(will trigger within a minute)
Jobs are considered unique for most of each minute, which prevents duplicate jobs with multiple nodes and across node restarts.
Unique Jobs
Uniqueness is based on a combination of args, queue, worker, state and insertion time.
Can be configured for worker
Or for specific job
Setup
1) Install oban dep
2) Migration
Place the follow in the newly created migration
3) Config
Config.exs
application.ex
Last updated