Sha256: e6bbb3bc5eaf7168571513d30f27dee1e2b49a8fa2228391674831caf774ad82
Contents?: true
Size: 1.25 KB
Versions: 2
Compression:
Stored size: 1.25 KB
Contents
require 'logger' module BackgroundWorker class Config attr_reader :logger, :enqueue_with, :backgrounded # Configuration includes following options: # logger: what logger to user throughout # enqueue_with: callback to execute the process # after_exception: callback to handle exceptions (for example, error reporting service) # # eg: # Config.new( # logger: Rails.logger, # enqueue_with: -> klass, method_name, opts { Resque.enqueue(klass, method_name, opts) }, # after_exception: -> e { Airbrake.notify(e) } # ) def initialize(attrs) @logger = attrs.fetch(:logger, ::Logger.new(STDOUT)) @enqueue_with = attrs.fetch(:enqueue_with, method(:foreground_enqueue)) @after_exception = attrs.fetch(:after_exception, method(:default_after_exception)) @backgrounded = attrs.fetch(:backgrounded, true) end # Callback fired when an exception occurs def after_exception(e) @after_exception.call(e) end def foreground_enqueue(klass, opts) klass.perform_now(opts) end def default_after_exception(e) logger.error '** No after_exception handler installed **' logger.error "Exception: #{e}" logger.error "#{e.backtrace.join("\n")}" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
background_worker-0.9.0 | lib/background_worker/config.rb |
background_worker-0.8.1 | lib/background_worker/config.rb |