lib/sucker_punch.rb in sucker_punch-1.6.0 vs lib/sucker_punch.rb in sucker_punch-2.0.0.beta1
- old
+ new
@@ -1,21 +1,58 @@
-require 'celluloid/current'
+require 'concurrent'
require 'sucker_punch/core_ext'
+require 'sucker_punch/counter'
require 'sucker_punch/job'
require 'sucker_punch/queue'
require 'sucker_punch/version'
+require 'logger'
module SuckerPunch
- def self.logger
- Celluloid.logger
- end
+ RUNNING = Concurrent::AtomicBoolean.new(true)
- def self.logger=(logger)
- Celluloid.logger = logger
- end
+ class << self
+ def exception_handler=(handler)
+ @exception_handler = handler
+ end
- def self.exception_handler(&block)
- Celluloid.exception_handler(&block)
+ def exception_handler
+ @exception_handler || method(:default_exception_handler)
+ end
+
+ def default_exception_handler(ex, klass, args)
+ msg = "Sucker Punch job error for class: '#{klass}' args: #{args}\n"
+ msg += "#{ex.class} #{ex}\n"
+ msg += "#{ex.backtrace.nil? ? '' : ex.backtrace.join("\n")}"
+ logger.error msg
+ end
+
+ def logger
+ @logger || default_logger
+ end
+
+ def logger=(log)
+ @logger = (log ? log : Logger.new('/dev/null'))
+ end
+
+ def default_logger
+ l = Logger.new(STDOUT)
+ l.level = Logger::INFO
+ l
+ end
+
+ def shutdown_timeout
+ # 10 seconds on heroku, minus a grace period
+ @shutdown_timeout || 8
+ end
+
+ def shutdown_timeout=(timeout)
+ @shutdown_timeout = timeout
+ end
end
+end
+
+at_exit do
+ SuckerPunch::Queue.shutdown_all
+ SuckerPunch.logger.info("All is quiet...byebye")
end
require 'sucker_punch/railtie' if defined?(::Rails)