Skip to content

Commit

Permalink
Do not scale down workers if there are more than one working worker.
Browse files Browse the repository at this point in the history
When after_perform_scale_down is called it will always have at least one working worker, which is itself, but it may have more workers working.

We can't just scale down based on the number of pending jobs, because if multiple jobs are queued at the same time and we have this many number of workers, we may have many working jobs and no pending job, yet we can't kill those workers.

By checking if there are any working workers besides the job itself we prevent this from happening.
  • Loading branch information
vicentemundim committed Sep 17, 2012
1 parent 4dc4881 commit b6ee7c3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/heroku-resque-auto-scale.rb
Expand Up @@ -16,12 +16,17 @@ def workers=(qty)
def job_count def job_count
Resque.info[:pending].to_i Resque.info[:pending].to_i
end end

def working_job_count
Resque.info[:working].to_i
end
end end
end end


def after_perform_scale_down(*args) def after_perform_scale_down(*args)
# Nothing fancy, just shut everything down if we have no jobs # Nothing fancy, just shut everything down if we have no pending jobs
Scaler.workers = 0 if Scaler.job_count.zero? # and one working job (which is this job)
Scaler.workers = 0 if Scaler.job_count.zero? && Scaler.working_job_count == 1
end end


def after_enqueue_scale_up(*args) def after_enqueue_scale_up(*args)
Expand Down

0 comments on commit b6ee7c3

Please sign in to comment.