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



29
30
31
32
# File 'lib/background_queue/worker/base.rb', line 29

def add_progress_meta(key, value)
  logger.debug("add_progress_meta(#{key}, #{value.to_json})")
  self.environment.send_data({:meta=>{key=>value}}.to_json)
end

#append_summary(type, data) ⇒ Object



34
35
36
37
# File 'lib/background_queue/worker/base.rb', line 34

def append_summary(type, data)
  raise "Missing Type when appending summary" if type.nil?
  self.environment.send_data({:summary=>"app", :type=>type.to_s, :data=>data}.to_json)
end

#decrement_sumary(type, amount = 1) ⇒ Object



50
51
52
53
# File 'lib/background_queue/worker/base.rb', line 50

def decrement_sumary(type, amount=1)
  raise "Missing Type when decrementing summary" if type.nil?
  self.environment.send_data({:summary=>"dec", :type=>type.to_s, :data=>amount}.to_json)
end

#environmentObject



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

def environment
  @environment
end

#finishObject

virtual function: called to process a worker request (step=finish)



70
71
72
# File 'lib/background_queue/worker/base.rb', line 70

def finish
  raise "finish() Not Implemented on worker #{self.class.name}"
end

#increment_summary(type, amount = 1) ⇒ Object



45
46
47
48
# File 'lib/background_queue/worker/base.rb', line 45

def increment_summary(type, amount=1)
  raise "Missing Type when incrementing summary" if type.nil?
  self.environment.send_data({:summary=>"inc", :type=>type.to_s, :data=>amount}.to_json)
end

#loggerObject



78
79
80
# File 'lib/background_queue/worker/base.rb', line 78

def logger
  self.environment.logger
end

#paramsObject



74
75
76
# File 'lib/background_queue/worker/base.rb', line 74

def params
  self.environment.params
end

#reset_summary(type) ⇒ Object



55
56
57
# File 'lib/background_queue/worker/base.rb', line 55

def reset_summary(type)
  self.environment.send_data({:summary=>"res", :type=>type.to_s}.to_json)
end

#runObject

virtual function: called to process a worker request



60
61
62
# File 'lib/background_queue/worker/base.rb', line 60

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
24
# File 'lib/background_queue/worker/base.rb', line 19

def set_progress(caption, percent)
  #puts self
  #puts "env=#{self.environment}"
  logger.debug("set_progress(#{caption}, #{percent})")
  self.environment.send_data({:caption=>caption, :percent=>percent}.to_json)
end

#set_summary(type, key, data) ⇒ Object



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

def set_summary(type, key, data)
  raise "Missing Type when settind summary" if type.nil?
  raise "Missing key when settind summary" if key.nil?
  self.environment.send_data({:summary=>"set", :type=>type.to_s, :key=>key, :data=>data}.to_json)
end

#startObject

virtual function: called to process a worker request (step=start)



65
66
67
# File 'lib/background_queue/worker/base.rb', line 65

def start
  raise "start() Not Implemented on worker #{self.class.name}"
end

#summaryObject



82
83
84
# File 'lib/background_queue/worker/base.rb', line 82

def summary
  self.environment.summary
end