Module: QueueProcessor::DependentCalculation::QueueControl
Defined Under Namespace
Classes: CalculationRequest
Instance Method Summary
collapse
Instance Method Details
#add_to_queue ⇒ Object
25
26
27
28
|
# File 'lib/queue-processor/dependent_calculation/queue_control.rb', line 25
def add_to_queue
update_attribute(:queued_at, Time.now.utc)
Delayed::Job.enqueue(CalculationRequest.new(id, queued_at, describe, self.class), delayed_job_options)
end
|
#delayed_job_options ⇒ Object
34
35
36
|
# File 'lib/queue-processor/dependent_calculation/queue_control.rb', line 34
def delayed_job_options
{:priority=>priority, :run_at => run_at, :queue => queue}.reject {|k,v| v.nil?}
end
|
#delayed_jobs ⇒ Object
11
12
13
|
# File 'lib/queue-processor/dependent_calculation/queue_control.rb', line 11
def delayed_jobs
Delayed::Backend::ActiveRecord::Job.where("handler ilike '%QueueProcessor::DependentCalculation::QueueControl::CalculationRequest%' and handler like '%id: #{id}%'")
end
|
#describe ⇒ Object
7
8
9
|
# File 'lib/queue-processor/dependent_calculation/queue_control.rb', line 7
def describe
"DependentCalculation: #{self.id}"
end
|
#in_queue? ⇒ Boolean
30
31
32
|
# File 'lib/queue-processor/dependent_calculation/queue_control.rb', line 30
def in_queue?
delayed_jobs.count > 0
end
|
#process_queued_calculation ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/queue-processor/dependent_calculation/queue_control.rb', line 15
def process_queued_calculation
unless parent_calculation && parent_calculation.should_cancel?
self.perform_calculation
end
self.update(:completed => true)
Rails.logger.debug {"#{self.describe}: is done"}
parent_calculation&.fire_events(:finish)
end
|