Module: Postburner::Insertion
- Extended by:
- ActiveSupport::Concern
- Included in:
- Job
- Defined in:
- app/concerns/postburner/insertion.rb
Overview
Concern providing queue insertion methods for Postburner jobs.
Handles enqueuing jobs to Beanstalkd (or test strategies), including scheduling, re-queueing, and the internal insertion mechanics via after_save_commit callbacks.
Instance Method Summary collapse
-
#queue!(options = {}) ⇒ true
Enqueues the job to Beanstalkd for processing.
-
#requeue!(options = {}) ⇒ true
Re-queues an existing job by removing it from Beanstalkd and queueing again.
-
#will_insert? ⇒ Boolean
private
Checks if job is flagged for insertion into Beanstalkd.
Instance Method Details
#queue!(options = {}) ⇒ true
Enqueues the job to Beanstalkd for processing.
Sets queued_at timestamp and optionally run_at for scheduled execution. Triggers enqueue callbacks and inserts job into Beanstalkd via after_save_commit hook. In test mode, executes immediately instead of queueing to Beanstalkd.
71 72 73 74 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 |
# File 'app/concerns/postburner/insertion.rb', line 71 def queue!(={}) return true if self.queued_at.present? && self.bkid.present? raise ActiveRecord::RecordInvalid, "Can't queue unless valid." unless self.valid? raise AlreadyProcessed, "Processed at #{self.processed_at}" if self.processed_at # Extract and set instance-level overrides self.priority = .delete(:priority) if .key?(:priority) self.ttr = .delete(:ttr) if .key?(:ttr) self.queue_name = .delete(:queue) if .key?(:queue) at = .delete(:at) now = Time.current self.queued_at = now self.run_at = case when at.present? # this is rudimentary, add error handling [:delay] ||= at.to_i - now.to_i at when [:delay].present? now + [:delay].seconds end @_insert_options = run_callbacks :enqueue do self.save! end true end |
#requeue!(options = {}) ⇒ true
Re-queues an existing job by removing it from Beanstalkd and queueing again.
Calls #delete! to remove from Beanstalkd, resets queuing metadata, then calls #queue! with new options.
126 127 128 129 130 131 |
# File 'app/concerns/postburner/insertion.rb', line 126 def requeue!(={}) self.delete! self.bkid, self.queued_at = nil, nil self.queue! end |
#will_insert? ⇒ Boolean
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.
Checks if job is flagged for insertion into Beanstalkd.
Set internally by #queue! to trigger insertion via after_save_commit hook.
140 141 142 |
# File 'app/concerns/postburner/insertion.rb', line 140 def will_insert? @_insert_options.is_a? Hash end |