Class: Postburner::DefaultQueue
- Inherits:
-
StrictQueue
- Object
- StrictQueue
- Postburner::DefaultQueue
- Defined in:
- lib/postburner/strategies/default_queue.rb
Overview
This is the DEFAULT strategy set on Postburner initialization
Default production queue strategy with graceful handling of premature execution.
This is the recommended production strategy and the default for Postburner. Unlike the strict StrictQueue strategy, DefaultQueue automatically re-inserts jobs that are executed before their scheduled run_at time, ensuring they run at the correct time without raising exceptions.
## When to Use DefaultQueue
Choose this strategy for production environments:
-
**Default choice:** This should be your go-to production strategy
-
**Graceful recovery:** Automatically handles scheduling edge cases
-
**Worker restarts:** Handles jobs picked up during worker restarts
-
**Clock drift:** Tolerates minor time synchronization issues
-
**Robust operation:** Prevents job failures due to timing issues
This strategy provides the most forgiving and robust behavior for production systems where you want scheduled jobs to execute correctly even if workers pick them up slightly early.
## Strategy Behavior
-
Execution: Asynchronous via Beanstalkd workers
-
**Testing mode:** Returns false
-
**Premature execution:** Re-inserts job with calculated delay, logs the event
-
Beanstalkd: Required and used for all job queueing
## How Premature Execution Works
When a job is executed before its run_at time:
-
Calculates remaining delay: ‘job.run_at - Time.zone.now`
-
Re-inserts job to Beanstalkd with calculated delay
-
Logs “PREMATURE; RE-INSERTED” message to job logs
-
Returns without executing the job
-
Job executes normally when picked up at the correct time
## Usage
Class Method Summary collapse
-
.handle_premature_perform(job) ⇒ void
Handles jobs executed before their scheduled run_at time.
Methods inherited from StrictQueue
handle_perform!, insert, testing
Class Method Details
.handle_premature_perform(job) ⇒ void
Logs “PREMATURE; RE-INSERTED” message to job’s audit trail
This method returns an undefined value.
Handles jobs executed before their scheduled run_at time.
Unlike the parent StrictQueue strategy, DefaultQueue gracefully handles premature execution by re-inserting the job with the appropriate delay instead of raising an exception.
79 80 81 82 |
# File 'lib/postburner/strategies/default_queue.rb', line 79 def handle_premature_perform(job) response = job.insert! delay: job.run_at - Time.current job.log! "PREMATURE; RE-INSERTED: #{response}" end |