agent_propagate_job.rb 673 B

1234567891011121314151617181920
  1. class AgentPropagateJob < ActiveJob::Base
  2. queue_as :propagation
  3. def perform
  4. Agent.receive!
  5. end
  6. def self.can_enqueue?
  7. case queue_adapter.class.name # not using class since it would load adapter dependent gems
  8. when 'ActiveJob::QueueAdapters::DelayedJobAdapter'
  9. return Delayed::Job.where(failed_at: nil, queue: 'propagation').count == 0
  10. when 'ActiveJob::QueueAdapters::ResqueAdapter'
  11. return Resque.size('propagation') == 0 &&
  12. Resque.workers.select { |w| w.job && w.job['queue'] && w.job['queue']['propagation'] }.count == 0
  13. else
  14. raise NotImplementedError, "unsupported adapter: #{queue_adapter}"
  15. end
  16. end
  17. end