Class: Postburner::NullQueue
- Inherits:
-
TestQueue
- Object
- TestQueue
- Postburner::NullQueue
- Extended by:
- TimeHelpers
- Defined in:
- lib/postburner/strategies/null_queue.rb
Overview
This is a test-mode strategy (returns true for testing)
Null queue strategy for creating jobs without queueing to Beanstalkd.
This strategy creates job records in the database but does NOT queue them to Beanstalkd. Jobs can be manually executed later using NullQueue.handle_perform!, which includes automatic time travel for scheduled jobs.
## When to Use NullQueue
Choose this strategy when you want:
-
**Deferred batch processing:** Create many jobs upfront, execute them manually later
-
**Conditional execution:** Queue jobs that may or may not execute based on runtime conditions
-
Testing/debugging: Inspect jobs before execution without auto-execution
-
**Manual control:** Explicitly control when jobs execute
-
**No Beanstalkd:** Create jobs without requiring Beanstalkd server
## Strategy Behavior
-
Execution: Manual via NullQueue.handle_perform! call
-
**Testing mode:** Returns true
-
Queueing: Jobs created in database but NOT sent to Beanstalkd
-
Beanstalkd: Not used (bkid remains nil)
-
**Time travel:** Automatic for scheduled jobs during manual execution
## Usage
Class Method Summary collapse
-
.handle_perform!(job) ⇒ void
private
Executes a job with automatic time travel for scheduled jobs.
-
.insert(job, options = {}) ⇒ Hash
private
Does NOT insert job into Beanstalkd queue.
Methods included from TimeHelpers
Class Method Details
.handle_perform!(job) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Executes a job with automatic time travel for scheduled jobs.
Called by Job.perform when NullQueue strategy is active. If the job has a future run_at, it automatically travels to that time before execution. Otherwise executes immediately.
Users should call Job.perform instead of this method directly.
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/postburner/strategies/null_queue.rb', line 120 def handle_perform!(job) if job.run_at && job.run_at > Time.current travel_to(job.run_at) do job.perform!(job.args) end else # No future run_at, execute normally job.perform!(job.args) end end |
.insert(job, options = {}) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Does NOT insert job into Beanstalkd queue.
Called automatically via after_save_commit hook when Job#queue! is invoked. Unlike other strategies, this does NOT queue to Beanstalkd - it only creates the job record in the database.
90 91 92 93 |
# File 'lib/postburner/strategies/null_queue.rb', line 90 def insert(job, = {}) # Return format matching Beanstalkd response (symbol keys) { status: 'NULL', id: nil } end |