Class: Dalliance::Workers::DelayedJob
- Inherits:
-
Struct
- Object
- Struct
- Dalliance::Workers::DelayedJob
- Defined in:
- lib/dalliance/workers/delayed_job.rb,
lib/dalliance/workers/delayed_job.rb
Instance Attribute Summary collapse
-
#instance_id ⇒ Object
Returns the value of attribute instance_id.
-
#instance_klass ⇒ Object
Returns the value of attribute instance_klass.
-
#perform_method ⇒ Object
Returns the value of attribute perform_method.
Class Method Summary collapse
- .dequeue(_instance) ⇒ Object
- .enqueue(instance, queue = 'dalliance', perform_method) ⇒ Object
- .queued?(instance, queue) ⇒ Boolean
-
.rescue_error? ⇒ Boolean
Delayed job automatically retries, so rescue the error.
Instance Method Summary collapse
Instance Attribute Details
#instance_id ⇒ Object
Returns the value of attribute instance_id
42 43 44 |
# File 'lib/dalliance/workers/delayed_job.rb', line 42 def instance_id @instance_id end |
#instance_klass ⇒ Object
Returns the value of attribute instance_klass
42 43 44 |
# File 'lib/dalliance/workers/delayed_job.rb', line 42 def instance_klass @instance_klass end |
#perform_method ⇒ Object
Returns the value of attribute perform_method
42 43 44 |
# File 'lib/dalliance/workers/delayed_job.rb', line 42 def perform_method @perform_method end |
Class Method Details
.dequeue(_instance) ⇒ Object
13 14 15 |
# File 'lib/dalliance/workers/delayed_job.rb', line 13 def self.dequeue(_instance) # NOP end |
.enqueue(instance, queue = 'dalliance', perform_method) ⇒ Object
7 8 9 10 11 |
# File 'lib/dalliance/workers/delayed_job.rb', line 7 def self.enqueue(instance, queue = 'dalliance', perform_method) Dalliance::Workers::DelayedJob .set(queue: queue) .perform_later(instance.class.name, instance.id, perform_method.to_s) end |
.queued?(instance, queue) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dalliance/workers/delayed_job.rb', line 17 def self.queued?(instance, queue) queued_jobs = Delayed::Job.where(queue: queue) .pluck(:handler) .map(&YAML.method(:load)) queued_jobs.any? do |job_wrapper| job_wrapper.job_data['arguments'].first(2) == [instance.class.name, instance.id] end end |
.rescue_error? ⇒ Boolean
Delayed job automatically retries, so rescue the error
37 38 39 |
# File 'lib/dalliance/workers/delayed_job.rb', line 37 def self.rescue_error? true end |
Instance Method Details
#perform ⇒ Object
29 30 31 32 33 34 |
# File 'lib/dalliance/workers/delayed_job.rb', line 29 def perform(instance_klass, instance_id, perform_method) instance_klass .constantize .find(instance_id) .send(perform_method, true) end |