Module: HerokuResqueAutoScale

Included in:
ProcessImage
Defined in:
lib/heroku_resque_auto_scale.rb

Defined Under Namespace

Modules: Scaler

Instance Method Summary collapse

Instance Method Details

#after_enqueue_scale_up(*args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/heroku_resque_auto_scale.rb', line 28

def after_enqueue_scale_up(*args)
  [
    {
      :workers => 1, # This many workers
      :job_count => 1 # For this many jobs or more, until the next level
    },
    {
      :workers => 2,
      :job_count => 5
    },
    {
      :workers => 3,
      :job_count => 15
    },
    {
      :workers => 4,
      :job_count => 20
    },
    {
      :workers => 5,
      :job_count => 25
    }
  ].reverse_each do |scale_info|
    # Run backwards so it gets set to the highest value first
    # Otherwise if there were 70 jobs, it would get set to 1, then 2, then 3, etc
   
    # If we have a job count greater than or equal to the job limit for this scale info
    if Scaler.job_count >= scale_info[:job_count]
      # Set the number of workers unless they are already set to a level we want. Don't scale down here!
      if Scaler.workers <= scale_info[:workers]
        Scaler.workers = scale_info[:workers]
      end
      break # We've set or ensured that the worker count is high enough
    end
  end
end

#after_perform_scale_down(*args) ⇒ Object



23
24
25
26
# File 'lib/heroku_resque_auto_scale.rb', line 23

def after_perform_scale_down(*args)
  # Nothing fancy, just shut everything down if we have no jobs
  Scaler.workers = 0 if Scaler.job_count.zero?
end