Oban.Job.new
You're seeing just the function
new
, go back to Oban.Job module for more information.
Specs
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:meta
— a map containing additional information about the job:priority
— a numerical indicator from 0 to 3 of how important this job is relative to other jobs in the same queue. The lower the number, the higher priority the job.: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:replace_args
- if the arguments should be replaced on a unique conflict:replace
- a list of keys to replace on a unique conflict:scheduled_at
- a time in the future after which the job should be executed:tags
— a list of tags to group and organize related jobs, i.e. to identify scheduled jobs:unique
— a keyword list of options specifying how uniqueness will be calculated. The options define which fields will be used, for how long, with which keys, and for which states.:worker
— a module to execute the job in. The module must implement theOban.Worker
behaviour.
Examples
Insert a job with the :default
queue:
%{id: 1, user_id: 2}
|> Oban.Job.new(queue: :default, worker: MyApp.Worker)
|> Oban.insert()
Generate a pre-configured job for MyApp.Worker
and push it:
%{id: 1, user_id: 2} |> MyApp.Worker.new() |> Oban.insert()
Schedule a job to run in 5 seconds:
%{id: 1} |> MyApp.Worker.new(schedule_in: 5) |> Oban.insert()
Insert a job, ensuring that it is unique within the past minute:
%{id: 1} |> MyApp.Worker.new(unique: [period: 60]) |> Oban.insert()
Insert a unique job based only on the worker field, and within multiple states:
fields = [:worker]
states = [:available, :scheduled, :executing, :retryable, :completed]
%{id: 1}
|> MyApp.Worker.new(unique: [fields: fields, period: 60, states: states])
|> Oban.insert()
Insert a unique job considering only the worker and specified keys in the args:
keys = [:account_id, :url]
%{account_id: 1, url: "https://example.com"}
|> MyApp.Worker.new(unique: [fields: [:args, :worker], keys: keys])
|> Oban.insert()