lib/workless/scaler.rb in workless_revived-1.2.5 vs lib/workless/scaler.rb in workless_revived-2.0.0
- old
+ new
@@ -1,20 +1,25 @@
module Delayed
module Workless
module Scaler
autoload :Heroku, 'workless/scalers/heroku'
- autoload :HerokuCedar, 'workless/scalers/heroku_cedar'
autoload :Local, 'workless/scalers/local'
autoload :Null, 'workless/scalers/null'
def self.included(base)
base.send :extend, ClassMethods
if base.to_s =~ /ActiveRecord/
base.class_eval do
- after_commit 'self.class.scaler.down'.to_sym, on: :update, if: proc { |r| !r.failed_at.nil? }
- after_commit 'self.class.scaler.down'.to_sym, on: :destroy, if: proc { |r| r.destroyed? || !r.failed_at.nil? }
- after_commit 'self.class.scaler.up'.to_sym, on: :create
+ after_commit(on: :update, if: proc { |r| !r.failed_at.nil? }) do
+ self.class.scaler.down
+ end
+ after_commit(on: :destroy, if: proc { |r| r.destroyed? || !r.failed_at.nil? }) do
+ self.class.scaler.down
+ end
+ after_commit(on: :create) do
+ self.class.scaler.up
+ end
end
elsif base.to_s =~ /Sequel/
base.send(:define_method, 'after_destroy') do
super
self.class.scaler.down
@@ -37,10 +42,10 @@
end
module ClassMethods
def scaler
@scaler ||= if ENV.include?('HEROKU_API_KEY')
- Scaler::HerokuCedar
+ Scaler::Heroku
else
Scaler::Local
end
end