lib/dyno_scaler/workers/resque.rb in dyno_scaler-0.2.0 vs lib/dyno_scaler/workers/resque.rb in dyno_scaler-0.3.0

- old
+ new

@@ -13,10 +13,14 @@ enable_scaling_up enable_scaling_down end + def scale(&block) + self.class.scale(&block) + end + module ClassMethods 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 @@ -25,11 +29,11 @@ rescue StandardError => e $stderr.puts "Could not scale down workers: #{e}" end def after_enqueue_scale_up(*args) - if scale_up_enabled? + 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 @@ -50,9 +54,21 @@ self.scale_up_enabled = false end def disable_scaling_down self.scale_down_enabled = false + end + + def scaling? + @scaling + end + + def scale(&block) + @scaling = true + result = block.call if block_given? + dyno_scaler_manager.scale_with(::Resque.info) + @scaling = false + result end private def dyno_scaler_manager @manager ||= DynoScaler::Manager.new