Class: BackgroundQueue::Worker::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/background_queue/worker/base.rb

Overview

the base class of workers

Instance Method Summary collapse

Constructor Details

#initializeBase

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 add_progress_meta(key, value)
  self.environment.send_data({:meta=>{key=>value}}.to_json)
end

#environmentObject



14
15
16
# File 'lib/background_queue/worker/base.rb', line 14

def environment
  @environment
end

#loggerObject



41
42
43
# File 'lib/background_queue/worker/base.rb', line 41

def logger
  self.environment.logger
end

#paramsObject



37
38
39
# File 'lib/background_queue/worker/base.rb', line 37

def params
  self.environment.params
end

#runObject

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(caption, percent)
  #puts self
  #puts "env=#{self.environment}"
  self.environment.send_data({:caption=>caption, :percent=>percent}.to_json)
end