Class: Upperkut::WorkerThread

Inherits:
Object
  • Object
show all
Defined in:
lib/upperkut/worker_thread.rb

Instance Method Summary collapse

Constructor Details

#initialize(manager, processor) ⇒ WorkerThread

Returns a new instance of WorkerThread.



5
6
7
8
# File 'lib/upperkut/worker_thread.rb', line 5

def initialize(manager, processor)
  @manager = manager
  @processor = processor
end

Instance Method Details

#killObject



30
31
32
33
34
35
# File 'lib/upperkut/worker_thread.rb', line 30

def kill
  return unless @thread

  @thread.raise Upperkut::Shutdown
  @thread.value # wait
end

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/upperkut/worker_thread.rb', line 10

def run
  @thread ||= Thread.new do
    begin
      @processor.blocking_process
    rescue Exception => e
      @manager.logger.debug(
        action: :processor_killed,
        reason: e,
        stacktrace: e.backtrace
      )

      @manager.notify_killed_processor(self)
    end
  end
end

#stopObject



26
27
28
# File 'lib/upperkut/worker_thread.rb', line 26

def stop
  @processor.stop
end