Class: Philiprehberger::TaskQueue::Worker
- Inherits:
-
Object
- Object
- Philiprehberger::TaskQueue::Worker
- Defined in:
- lib/philiprehberger/task_queue/worker.rb
Overview
Worker processes tasks from the queue in a dedicated thread.
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(queue, mutex, condition, context:) ⇒ Worker
constructor
A new instance of Worker.
- #stop ⇒ Object
Constructor Details
#initialize(queue, mutex, condition, context:) ⇒ Worker
Returns a new instance of Worker.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/philiprehberger/task_queue/worker.rb', line 9 def initialize(queue, mutex, condition, context:) @queue = queue @mutex = mutex @condition = condition @stats = context[:stats] @error_handler = context[:error_handler] @complete_handler = context[:complete_handler] @drain_condition = context[:drain_condition] @paused = context[:paused] @pause_condition = context[:pause_condition] @running = true @thread = Thread.new { run } end |
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
7 8 9 |
# File 'lib/philiprehberger/task_queue/worker.rb', line 7 def thread @thread end |
Instance Method Details
#alive? ⇒ Boolean
27 28 29 |
# File 'lib/philiprehberger/task_queue/worker.rb', line 27 def alive? @thread&.alive? || false end |
#stop ⇒ Object
23 24 25 |
# File 'lib/philiprehberger/task_queue/worker.rb', line 23 def stop @running = false end |