Module: BackgroundWorker

Defined in:
lib/background_worker/uid.rb,
lib/background_worker.rb,
lib/background_worker/base.rb,
lib/background_worker/config.rb,
lib/background_worker/version.rb,
lib/background_worker/persistent_state.rb,
lib/background_worker/worker_execution.rb

Overview

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.

Defined Under Namespace

Classes: Base, Config, PersistentState, Uid, WorkerExecution

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.after_exception(e) ⇒ Object



33
34
35
# File 'lib/background_worker.rb', line 33

def self.after_exception(e)
  config.after_exception(e)
end

.configObject



37
38
39
40
# File 'lib/background_worker.rb', line 37

def self.config
  fail 'Not configured!' unless @config
  @config
end

.configure(options) ⇒ Object

Configure worker

eg: BackgroundWorker.configure(

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

)



14
15
16
# File 'lib/background_worker.rb', line 14

def self.configure(options)
  @config = Config.new(options)
end

.enqueue(klass, method_name, options) ⇒ Object



18
19
20
# File 'lib/background_worker.rb', line 18

def self.enqueue(klass, method_name, options)
  config.enqueue_with.call(klass, method_name, options)
end

.loggerObject



22
23
24
# File 'lib/background_worker.rb', line 22

def self.logger
  config.logger
end

.verify_active_connections!Object



26
27
28
29
30
31
# File 'lib/background_worker.rb', line 26

def self.verify_active_connections!
  Rails.cache.reconnect if defined?(Rails)
  if defined?(ActiveRecord) && ActiveRecord::VERSION::MAJOR == 3
    ActiveRecord::Base.verify_active_connections!
  end
end