Class: Postburner::InlineTestQueue
- Inherits:
-
StrictQueue
- Object
- StrictQueue
- Postburner::InlineTestQueue
- Defined in:
- lib/postburner/strategies/inline_test_queue.rb
Overview
Auto-detected when Rails.env.test? and ActiveJob adapter is :test
Inline test queue strategy with strict scheduling enforcement.
This strategy executes jobs inline/synchronously without Beanstalkd, making tests fast and predictable. It raises Job::PrematurePerform if a job has a future run_at, forcing you to use explicit time travel in tests.
## When to Use InlineTestQueue
Choose this strategy for test environments where you want:
-
**Explicit time management:** Forces you to use ‘travel_to` for scheduled jobs
-
**Strict testing:** Catches scheduling bugs by failing loudly
-
**Synchronous execution:** Jobs run immediately on ‘queue!` call
-
**No Beanstalkd:** Tests run without external dependencies
-
**Predictable timing:** Full control over when jobs execute
This is ideal for unit/integration tests where you want to verify job scheduling logic and maintain explicit control over time progression.
## Strategy Behavior
-
Execution: Synchronous/inline (no Beanstalkd required)
-
**Testing mode:** Returns true
-
**Premature execution:** Raises Job::PrematurePerform exception
-
Beanstalkd: Not used (bkid remains nil)
-
**Time travel:** Requires explicit ‘travel_to` for scheduled jobs
## Usage
Direct Known Subclasses
Class Method Summary collapse
-
.handle_premature_perform(job) ⇒ void
Handles jobs executed before their scheduled run_at time.
-
.insert(job, options = {}) ⇒ Hash
private
Executes job inline/synchronously without Beanstalkd.
-
.testing ⇒ Boolean
Returns whether this strategy is for testing.
Methods inherited from StrictQueue
Class Method Details
.handle_premature_perform(job) ⇒ void
This method returns an undefined value.
Handles jobs executed before their scheduled run_at time.
This strategy raises an exception with a helpful error message, forcing developers to use explicit ‘travel_to` calls in tests.
123 124 125 |
# File 'lib/postburner/strategies/inline_test_queue.rb', line 123 def handle_premature_perform(job) raise Postburner::Job::PrematurePerform, "Job scheduled for #{job.run_at} (#{((job.run_at - Time.current) / 60).round(1)} minutes from now). Use `travel_to(job.run_at)` in your test, or set `Postburner.time_travel_test_strategy!` i.e. `Postburner::TimeTravelTestQueue` to execute scheduled jobs immediately." 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.
Executes job inline/synchronously without Beanstalkd.
Called automatically via after_save_commit hook when Job#queue! is invoked. Executes the job immediately in the same process. If the job has a future run_at, raises Job::PrematurePerform to force explicit time management with ‘travel_to`.
103 104 105 106 107 108 109 110 |
# File 'lib/postburner/strategies/inline_test_queue.rb', line 103 def insert(job, = {}) # Execute immediately in test mode # Will raise PrematurePerform if run_at is in the future job.perform!(job.args) # Return format matching Beanstalkd response (symbol keys) { status: 'INLINE', id: nil } end |
.testing ⇒ Boolean
Returns whether this strategy is for testing.
83 84 85 |
# File 'lib/postburner/strategies/inline_test_queue.rb', line 83 def testing true end |