Class: BackgroundQueue::Worker::Base
- Inherits:
-
Object
- Object
- BackgroundQueue::Worker::Base
- Defined in:
- lib/background_queue/worker/base.rb
Overview
the base class of workers
Instance Method Summary collapse
-
#add_progress_meta(key, value) ⇒ Object
add meta data to the progress key: :notice, :warning, :error, :meta value: :notice/:warning/:error : String, :meta : any json compatible object.
- #environment ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #logger ⇒ Object
- #params ⇒ Object
-
#run ⇒ Object
virtual function: called to process a worker request.
- #set_environment(env) ⇒ Object
-
#set_progress(caption, percent) ⇒ Object
update the progress of the currently running task.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
5 6 7 |
# File 'lib/background_queue/worker/base.rb', line 5 def initialize @environment = nil end |
Instance Method Details
#add_progress_meta(key, value) ⇒ Object
add meta data to the progress key: :notice, :warning, :error, :meta value: :notice/:warning/:error : String, :meta : any json compatible object
28 29 30 |
# File 'lib/background_queue/worker/base.rb', line 28 def (key, value) self.environment.send_data({:meta=>{key=>value}}.to_json) end |
#environment ⇒ Object
14 15 16 |
# File 'lib/background_queue/worker/base.rb', line 14 def environment @environment end |
#logger ⇒ Object
41 42 43 |
# File 'lib/background_queue/worker/base.rb', line 41 def logger self.environment.logger end |
#params ⇒ Object
37 38 39 |
# File 'lib/background_queue/worker/base.rb', line 37 def params self.environment.params end |
#run ⇒ Object
virtual function: called to process a worker request
33 34 35 |
# File 'lib/background_queue/worker/base.rb', line 33 def run raise "run() Not Implemented on worker #{self.class.name}" end |
#set_environment(env) ⇒ Object
9 10 11 12 |
# File 'lib/background_queue/worker/base.rb', line 9 def set_environment(env) #puts "set_environment=#{env}" @environment = env end |
#set_progress(caption, percent) ⇒ Object
update the progress of the currently running task
19 20 21 22 23 |
# File 'lib/background_queue/worker/base.rb', line 19 def set_progress(, percent) #puts self #puts "env=#{self.environment}" self.environment.send_data({:caption=>, :percent=>percent}.to_json) end |