Class: ThreadedInMemoryQueue::Worker
- Inherits:
-
Object
- Object
- ThreadedInMemoryQueue::Worker
- Includes:
- Timeout
- Defined in:
- lib/threaded_in_memory_queue/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.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(queue, options = {}) ⇒ Worker
constructor
A new instance of Worker.
- #join ⇒ Object
- #poison(times = 1) ⇒ Object
- #start ⇒ Object
- #thread ⇒ Object
Methods included from Timeout
Constructor Details
#initialize(queue, options = {}) ⇒ Worker
Returns a new instance of Worker.
8 9 10 11 12 |
# File 'lib/threaded_in_memory_queue/worker.rb', line 8 def initialize(queue, = {}) @queue = queue @timeout = [:timeout] || DEFAULT_TIMEOUT @logger = [:logger] || ThreadedInMemoryQueue.logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/threaded_in_memory_queue/worker.rb', line 6 def logger @logger end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
6 7 8 |
# File 'lib/threaded_in_memory_queue/worker.rb', line 6 def queue @queue end |
Instance Method Details
#alive? ⇒ Boolean
28 29 30 31 |
# File 'lib/threaded_in_memory_queue/worker.rb', line 28 def alive? return false unless @thread thread.alive? end |
#join ⇒ Object
33 34 35 36 |
# File 'lib/threaded_in_memory_queue/worker.rb', line 33 def join return false unless @thread thread.join end |
#poison(times = 1) ⇒ Object
24 25 26 |
# File 'lib/threaded_in_memory_queue/worker.rb', line 24 def poison(times = 1) @queue.enq(POISON) end |
#start ⇒ Object
19 20 21 22 |
# File 'lib/threaded_in_memory_queue/worker.rb', line 19 def start @thread ||= create_thread return self end |
#thread ⇒ Object
14 15 16 17 |
# File 'lib/threaded_in_memory_queue/worker.rb', line 14 def thread raise WorkerNotStarted, "Must start worker before using" unless @thread @thread end |