Module: BackgroundWorker
- Defined in:
- lib/background_worker/persistent_state.rb,
lib/background_worker.rb,
lib/background_worker/base.rb,
lib/background_worker/state.rb,
lib/background_worker/config.rb,
lib/background_worker/logging.rb,
lib/background_worker/version.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
Modules: Logging, State Classes: Base, Config, PersistentState, WorkerExecution
Constant Summary collapse
- VERSION =
'0.9.0'
Class Method Summary collapse
- .after_exception(e) ⇒ Object
- .config ⇒ Object
-
.configure(options) ⇒ Object
Configure worker.
- .enqueue(klass, options) ⇒ Object
- .logger ⇒ Object
- .release_connections! ⇒ Object
- .verify_active_connections! ⇒ Object
Class Method Details
.after_exception(e) ⇒ Object
37 38 39 |
# File 'lib/background_worker.rb', line 37 def self.after_exception(e) config.after_exception(e) end |
.config ⇒ Object
41 42 43 44 |
# File 'lib/background_worker.rb', line 41 def self.config fail 'Not configured!' unless @config @config end |
.configure(options) ⇒ Object
Configure worker
eg: BackgroundWorker.configure(
logger: Rails.logger,
enqueue_with: -> klass, opts { Resque.enqueue(klass, opts) },
after_exception: -> e { Airbrake.notify(e) }
)
14 15 16 |
# File 'lib/background_worker.rb', line 14 def self.configure() @config = Config.new() end |
.enqueue(klass, options) ⇒ Object
18 19 20 |
# File 'lib/background_worker.rb', line 18 def self.enqueue(klass, ) config.enqueue_with.call(klass, ) end |
.logger ⇒ Object
22 23 24 |
# File 'lib/background_worker.rb', line 22 def self.logger config.logger end |
.release_connections! ⇒ Object
33 34 35 |
# File 'lib/background_worker.rb', line 33 def self.release_connections! ActiveRecord::Base.clear_all_connections! end |
.verify_active_connections! ⇒ Object
26 27 28 29 30 31 |
# 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 |