Class: Threaded::Worker
- Inherits:
-
Object
- Object
- Threaded::Worker
- Includes:
- Timeout
- Defined in:
- lib/threaded/worker.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
seconds, 1 minute
60
- POISON =
"poison"
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(queue, options = {}) ⇒ Worker
constructor
A new instance of Worker.
- #join ⇒ Object
- #poison ⇒ Object
- #start ⇒ Object
Methods included from Timeout
Constructor Details
#initialize(queue, options = {}) ⇒ Worker
Returns a new instance of Worker.
8 9 10 11 12 13 |
# File 'lib/threaded/worker.rb', line 8 def initialize(queue, = {}) @queue = queue @timeout = [:timeout] || DEFAULT_TIMEOUT @logger = [:logger] || Threaded.logger @thread = create_thread end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/threaded/worker.rb', line 6 def logger @logger end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
6 7 8 |
# File 'lib/threaded/worker.rb', line 6 def queue @queue end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
6 7 8 |
# File 'lib/threaded/worker.rb', line 6 def thread @thread end |
Instance Method Details
#alive? ⇒ Boolean
23 24 25 |
# File 'lib/threaded/worker.rb', line 23 def alive? thread.alive? end |
#join ⇒ Object
27 28 29 |
# File 'lib/threaded/worker.rb', line 27 def join thread.join end |
#poison ⇒ Object
15 16 17 |
# File 'lib/threaded/worker.rb', line 15 def poison @queue.enq(POISON) end |
#start ⇒ Object
19 20 21 |
# File 'lib/threaded/worker.rb', line 19 def start puts "start is deprecated, thread is started when worker created" end |