Class: Temporalio::Worker::Runner Private

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalio/worker/runner.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A class used to manage the lifecycle of running any number of workers.

Instance Method Summary collapse

Constructor Details

#initialize(*workers) ⇒ Runner

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Runner.



9
10
11
12
13
14
15
16
17
18
# File 'lib/temporalio/worker/runner.rb', line 9

def initialize(*workers)
  if workers.empty?
    raise ArgumentError, 'Must be initialized with at least one worker'
  end

  @workers = workers
  @mutex = Mutex.new
  @started = false
  @shutdown = false
end

Instance Method Details

#run(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/temporalio/worker/runner.rb', line 20

def run(&block)
  @thread = Thread.current
  @started = true
  workers.each { |worker| worker.start(self) }

  block ? block.call : sleep
rescue Temporalio::Error::WorkerShutdown
  # Explicit shutdown requested, no need to raise
ensure
  @shutdown = true
  shutdown_workers
end

#shutdown(exception = Temporalio::Error::WorkerShutdown.new('Manual shutdown')) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
36
37
38
39
40
41
42
# File 'lib/temporalio/worker/runner.rb', line 33

def shutdown(exception = Temporalio::Error::WorkerShutdown.new('Manual shutdown'))
  mutex.synchronize do
    return unless running?

    @shutdown = true
  end

  # propagate shutdown to the running thread
  thread&.raise(exception)
end