huginn/app/jobs/agent_propagate_job.rb

21 lines
673 B
Ruby
Raw Permalink Normal View History

class AgentPropagateJob < ActiveJob::Base
queue_as :propagation
def perform
Agent.receive!
end
def self.can_enqueue?
2016-09-13 00:03:18 +02:00
case queue_adapter.class.name # not using class since it would load adapter dependent gems
when 'ActiveJob::QueueAdapters::DelayedJobAdapter'
return Delayed::Job.where(failed_at: nil, queue: 'propagation').count == 0
when 'ActiveJob::QueueAdapters::ResqueAdapter'
return Resque.size('propagation') == 0 &&
Resque.workers.select { |w| w.job && w.job['queue'] && w.job['queue']['propagation'] }.count == 0
else
raise NotImplementedError, "unsupported adapter: #{queue_adapter}"
end
end
end