Module: DynoScaler::Workers::Resque::ClassMethods

Defined in:
lib/dyno_scaler/workers/resque.rb

Instance Method Summary collapse

Instance Method Details

#after_enqueue_scale_up(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dyno_scaler/workers/resque.rb', line 33

def after_enqueue_scale_up(*args)
  if scale_up_enabled? && !scaling?
    if DynoScaler.configuration.async?
      DynoScaler.configuration.async.call(::Resque.info.merge(action: :scale_up))
    else
      dyno_scaler_manager.scale_up(::Resque.info)
    end
  end
rescue StandardError => e
  $stderr.puts "Could not scale up workers: #{e}"
end

#after_perform_scale_down(*args) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/dyno_scaler/workers/resque.rb', line 23

def after_perform_scale_down(*args)
  info = ::Resque.info
  working = info[:working] > 0 ? info[:working] - 1 : 0
  info.merge!(working: working) # we are not working anymore

  dyno_scaler_manager.scale_down(info) if scale_down_enabled?
rescue StandardError => e
  $stderr.puts "Could not scale down workers: #{e}"
end

#disable_scaling_downObject



57
58
59
# File 'lib/dyno_scaler/workers/resque.rb', line 57

def disable_scaling_down
  self.scale_down_enabled = false
end

#disable_scaling_upObject



53
54
55
# File 'lib/dyno_scaler/workers/resque.rb', line 53

def disable_scaling_up
  self.scale_up_enabled = false
end

#enable_scaling_downObject



49
50
51
# File 'lib/dyno_scaler/workers/resque.rb', line 49

def enable_scaling_down
  self.scale_down_enabled = true
end

#enable_scaling_upObject



45
46
47
# File 'lib/dyno_scaler/workers/resque.rb', line 45

def enable_scaling_up
  self.scale_up_enabled = true
end

#scale(&block) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/dyno_scaler/workers/resque.rb', line 65

def scale(&block)
  @scaling = true
  result = block.call if block_given?
  dyno_scaler_manager.scale_with(::Resque.info)
  @scaling = false
  result
end

#scaling?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/dyno_scaler/workers/resque.rb', line 61

def scaling?
  @scaling
end