The doc of
Transition jobs to the
available state when they reach their scheduled time.
This module is necessary for the execution of scheduled and retryable jobs.
In my limited experience, I think when a job is created in Oban, it is scheduled. Then, the job will run at the scheduled time.
But, the doc said “This module is necessary for the execution of scheduled and retryable jobs.”. This makes me confused – if a job is scheduled when it is created, why I need another pluigin for transforming its state?
I have no idea about which scenario does
Can you guys give me some tips? Thanks in advance.
The stager is responsible for two things:
- Moving jobs in the
scheduled state to the
available state on or after their
- Notifying queues, through pubsub, that they have available jobs. This prevents every queue from polling independently to reduce DB load.
The stager is essential to Oban functioning properly, beyond just for scheduled jobs. As such, it’s started by each Oban instance automatically unless you have
Edit: Oban jobs have distinct states to mark whether they are available for execution, executing currently, etc.
Thanks for your reply. It has solved my confusion.
You mentioned the distinct states.
As far as I know, all available states can be found by using
[:scheduled, :available, :executing, :retryable, :completed, :discarded, :cancelled]
About the transition between states, I have a note:
:scheduled - When a job is created, its state is
:available - When a job is on or after their
scheduled_at timestamp, its state will be changed to
:executing - When a job is
:available, Oban will try to run it, and its state will changed to
:retryable: When a job is failed, the state will be changed to
:retryable before exceeding the number of retries. Then, its state will changed to
:available again by
:completed: A job is completed.
:discarded: A job is failed, and the number of retries has reached the job’s
:cancelled: A job is cancelled intentionally.
Is this note right?
I think this note would be helpful to the newcomers.
I want to contribute the note to the doc of Oban.Job.html#states/0. Is that fine?
That’s close. The only correction is that jobs are inserted as
available unless they are scheduled in the future, then they are
A docs contribution is absolutely welcome.