Oban v0.5.0 Oban.Job View Source

A Job is an Ecto schema used for asynchronous execution.

Job changesets are created by your application code and inserted into the database for asynchronous execution. Jobs can be inserted along with other application data as part of a transaction, which guarantees that jobs will only be triggered from a successful transaction.

Link to this section Summary

Functions

Construct a new job changeset ready for insertion into the database.

Link to this section Types

Link to this type

errors() View Source
errors() :: [%{at: DateTime.t(), attempt: pos_integer(), error: binary()}]

Link to this type

option() View Source
option() ::
  {:queue, atom() | binary()}
  | {:worker, atom() | binary()}
  | {:args, args()}
  | {:max_attempts, pos_integer()}
  | {:scheduled_at, DateTime.t()}
  | {:schedule_in, pos_integer()}

Link to this type

t() View Source
t() :: %Oban.Job{
  __meta__: term(),
  args: args(),
  attempt: non_neg_integer(),
  attempted_at: DateTime.t(),
  completed_at: DateTime.t(),
  errors: errors(),
  id: pos_integer(),
  inserted_at: DateTime.t(),
  max_attempts: pos_integer(),
  queue: binary(),
  scheduled_at: DateTime.t(),
  state: binary(),
  worker: binary()
}

Link to this section Functions

Construct a new job changeset ready for insertion into the database.

Options

  • :max_attempts — the maximum number of times a job can be retried if there are errors during execution
  • :queue — a named queue to push the job into. Jobs may be pushed into any queue, regardless of whether jobs are currently being processed for the queue.
  • :schedule_in - the number of seconds until the job should be executed
  • :scheduled_at - a time in the future after which the job should be executed
  • :worker — a module to execute the job in. The module must implement the Oban.Worker behaviour.

Examples

Insert a job with the :default queue:

%{id: 1, user_id: 2}
|> Oban.Job.new(queue: :default, worker: MyApp.Worker)
|> MyApp.Repo.insert()

Generate a pre-configured job for MyApp.Worker and push it:

%{id: 1, user_id: 2} |> MyApp.Worker.new() |> MyApp.Repo.insert()

Schedule a job to run in 5 seconds:

%{id: 1} |> MyApp.Worker.new(schedule_in: 5) |> MyApp.Repo.insert()