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.0.3'
Class Method Summary collapse
- .after_exception(e) ⇒ Object
- .config ⇒ Object
-
.configure(options) ⇒ Object
Configure worker.
- .enqueue(klass, method_name, options) ⇒ Object
- .logger ⇒ Object
- .verify_active_connections! ⇒ Object
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 |
.config ⇒ Object
37 38 39 40 |
# File 'lib/background_worker.rb', line 37 def self.config raise "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) }
)
16 17 18 |
# File 'lib/background_worker.rb', line 16 def self.configure() @config = Config.new() end |
.enqueue(klass, method_name, options) ⇒ Object
20 21 22 |
# File 'lib/background_worker.rb', line 20 def self.enqueue(klass, method_name, ) config.enqueue_with.call(klass, method_name, ) end |
.logger ⇒ Object
24 25 26 |
# File 'lib/background_worker.rb', line 24 def self.logger config.logger end |
.verify_active_connections! ⇒ Object
28 29 30 31 |
# File 'lib/background_worker.rb', line 28 def self.verify_active_connections! Rails.cache.reconnect if defined?(Rails) ActiveRecord::Base.verify_active_connections! if defined?(ActiveRecord) end |