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 Oban.Plugins.Stager for.
Can you guys give me some tips? Thanks in advance.
Moving jobs in the scheduled state to the available state on or after their scheduled_at timestamp.
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 plugins: false.
Edit: Oban jobs have distinct states to mark whether they are available for execution, executing currently, etc.
About the transition between states, I have a note:
:scheduled - When a job is created, its state is :scheduled.
:available - When a job is on or after their scheduled_at timestamp, its state will be changed to :available by Oban.Plugins.Stager.
:executing - When a job is :available, Oban will try to run it, and its state will changed to :executing.
: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 Oban.Plugins.Stager.
:completed: A job is completed.
:discarded: A job is failed, and the number of retries has reached the job’s :max_attempts.
: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?