Class: Philiprehberger::TaskQueue::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/philiprehberger/task_queue/worker.rb

Overview

Worker processes tasks from the queue in a dedicated thread.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#threadObject (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

Returns:

  • (Boolean)


27
28
29
# File 'lib/philiprehberger/task_queue/worker.rb', line 27

def alive?
  @thread&.alive? || false
end

#stopObject



23
24
25
# File 'lib/philiprehberger/task_queue/worker.rb', line 23

def stop
  @running = false
end