Class: Workerholic::Worker
- Inherits:
-
Object
- Object
- Workerholic::Worker
- Defined in:
- lib/workerholic/worker.rb
Overview
handles job execution in threads
Instance Attribute Summary collapse
-
#alive ⇒ Object
Returns the value of attribute alive.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
-
#initialize(queue = nil) ⇒ Worker
constructor
A new instance of Worker.
- #join ⇒ Object
- #kill ⇒ Object
- #work ⇒ Object
Constructor Details
#initialize(queue = nil) ⇒ Worker
Returns a new instance of Worker.
7 8 9 10 11 |
# File 'lib/workerholic/worker.rb', line 7 def initialize(queue=nil) @queue = queue @alive = true @logger = LogManager.new end |
Instance Attribute Details
#alive ⇒ Object
Returns the value of attribute alive.
5 6 7 |
# File 'lib/workerholic/worker.rb', line 5 def alive @alive end |
#queue ⇒ Object
Returns the value of attribute queue.
5 6 7 |
# File 'lib/workerholic/worker.rb', line 5 def queue @queue end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
4 5 6 |
# File 'lib/workerholic/worker.rb', line 4 def thread @thread end |
Instance Method Details
#join ⇒ Object
29 30 31 |
# File 'lib/workerholic/worker.rb', line 29 def join thread.join if thread end |
#kill ⇒ Object
25 26 27 |
# File 'lib/workerholic/worker.rb', line 25 def kill self.alive = false end |
#work ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/workerholic/worker.rb', line 13 def work @thread = Thread.new do while alive serialized_job = poll JobProcessor.new(serialized_job).process if serialized_job end end rescue ThreadError => e @logger.info(e.) raise Interrupt end |