Class: Resque::Plugins::ScalingCanary::CanaryJob

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/plugins/resque_heroku_scaling_canary/canary_job.rb

Class Method Summary collapse

Class Method Details

.canary_jobs_outstandingObject



21
22
23
# File 'lib/resque/plugins/resque_heroku_scaling_canary/canary_job.rb', line 21

def self.canary_jobs_outstanding
  Resque.size(@queue) + Resque.workers.find_all{ |w| w.processing["queue"] == @queue }.count
end

.non_canary_jobs_pendingObject



25
26
27
28
29
# File 'lib/resque/plugins/resque_heroku_scaling_canary/canary_job.rb', line 25

def self.non_canary_jobs_pending
  waiting = Resque.queues.reject{ |q| q == @queue}.inject(0){ |accum, item| accum += Resque.size(item) }
  being_processed = Resque.workers.find_all{ |w| w.processing["queue"] and w.processing["queue"] != @queue }.count
  waiting + being_processed
end

.perform(timeout) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/resque/plugins/resque_heroku_scaling_canary/canary_job.rb', line 10

def self.perform(timeout)
  before = self.non_canary_jobs_pending
  Kernel.sleep Config.polling_interval
  after = self.non_canary_jobs_pending
  if before == after and before == 0
    Config.heroku_client.ps_scale(Config.heroku_app, :type => "worker", :qty => 0)
  else
    Resque.enqueue(self, timeout)
  end
end