module BackgroundWorker

Progress reporter is used by background processes, to communicate with standard rails controllers.

It works by storing a hash of all progress-report data in a redis value keyed by the worker_uid.

Constants

VERSION

Public Class Methods

after_exception(e) click to toggle source
# File lib/background_worker.rb, line 37
def self.after_exception(e)
  config.after_exception(e)
end
config() click to toggle source
# File lib/background_worker.rb, line 41
def self.config
  fail 'Not configured!' unless @config
  @config
end
configure(options) click to toggle source

Configure worker

eg: BackgroundWorker.configure(

logger: Rails.logger,
enqueue_with: -> klass, opts { Resque.enqueue(klass, opts) },
after_exception: -> e { Airbrake.notify(e) }

)

# File lib/background_worker.rb, line 14
def self.configure(options)
  @config = Config.new(options)
end
enqueue(klass, options) click to toggle source
# File lib/background_worker.rb, line 18
def self.enqueue(klass, options)
  config.enqueue_with.call(klass, options)
end
logger() click to toggle source
# File lib/background_worker.rb, line 22
def self.logger
  config.logger
end
release_connections!() click to toggle source
# File lib/background_worker.rb, line 33
def self.release_connections!
  ActiveRecord::Base.clear_all_connections!
end
verify_active_connections!() click to toggle source
# File lib/background_worker.rb, line 26
def self.verify_active_connections!
  if defined?(Rails)
    Rails.cache.reconnect if Rails.cache.respond_to?(:reconnect)
    Rails.cache.redis.close if Rails.cache.respond_to?(:redis)
  end
end