Class: Postburner::StrictQueue
- Inherits:
-
Object
- Object
- Postburner::StrictQueue
- Defined in:
- lib/postburner/strategies/strict_queue.rb
Overview
This is NOT the default strategy - use DefaultQueue for production
Strict production queue strategy that queues jobs to Beanstalkd asynchronously.
This is the strict production strategy that raises an exception if a job is executed before its scheduled run_at time. Unlike DefaultQueue, it does not automatically re-insert premature jobs.
## When to Use StrictQueue
Choose this strategy when you want strict enforcement of job scheduling:
-
You want jobs to fail loudly if executed prematurely
-
You’re debugging scheduling issues
-
You want to catch configuration errors in production
For most production use cases, use DefaultQueue instead, which handles premature execution gracefully by re-inserting with appropriate delay.
## Strategy Behavior
-
Execution: Asynchronous via Beanstalkd workers
-
**Testing mode:** Returns false
-
**Premature execution:** Raises Job::PrematurePerform exception
-
Beanstalkd: Required and used for all job queueing
## Usage
Direct Known Subclasses
Class Method Summary collapse
- .handle_perform!(job) ⇒ Object
-
.handle_premature_perform(job) ⇒ void
Handles jobs executed before their scheduled run_at time.
-
.insert(job, options = {}) ⇒ Hash
private
Inserts job into Beanstalkd queue asynchronously.
-
.testing ⇒ Boolean
Returns whether this strategy is for testing.
Class Method Details
.handle_perform!(job) ⇒ Object
106 107 108 |
# File 'lib/postburner/strategies/strict_queue.rb', line 106 def handle_perform!(job) job.perform!(job.args) end |
.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 to fail loudly on premature execution. Override in subclasses (like NiceQueue) to handle differently.
121 122 123 |
# File 'lib/postburner/strategies/strict_queue.rb', line 121 def handle_premature_perform(job) raise Postburner::Job::PrematurePerform, "Job has future run_at: #{job.run_at}" 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.
Inserts job into Beanstalkd queue asynchronously.
Called automatically via after_save_commit hook when Job#queue! is invoked. Enqueues the job to Beanstalkd and returns the response. The bkid is updated by Job#insert! after this returns.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/postburner/strategies/strict_queue.rb', line 75 def insert(job, = {}) #debugger Postburner::Job.transaction do Postburner.connected do |conn| tube_name = job.tube_name data = { class: job.class.name, args: [job.id] } # Get priority, TTR from job instance (respects instance overrides) or options pri = [:pri] || job.priority || Postburner.configuration.default_priority delay = [:delay].present? ? [0, [:delay].to_i].max : 0 ttr = [:ttr] || job.ttr || Postburner.configuration.default_ttr payload = JSON.generate(data) begin response = conn.tubes[tube_name].put( payload, pri: pri, delay: delay, ttr: ttr ) rescue Beaneater::BadFormatError => e raise Postburner::Job::BadFormat.new( "Beanstalkd BAD_FORMAT: tube=#{tube_name} payload=#{payload} pri=#{pri.inspect} delay=#{delay.inspect} ttr=#{ttr.inspect}" ), cause: e end response end end end |
.testing ⇒ Boolean
Returns whether this strategy is for testing.
53 54 55 |
# File 'lib/postburner/strategies/strict_queue.rb', line 53 def testing false end |