Class: Temporalio::Worker::ActivityExecutor::Fiber

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

Overview

Activity executor for scheduling activites as fibers.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultFiber

Returns Default/shared Fiber executor instance.

Returns:

  • (Fiber)

    Default/shared Fiber executor instance.



12
13
14
# File 'lib/temporalio/worker/activity_executor/fiber.rb', line 12

def self.default
  @default ||= new
end

Instance Method Details

#activity_contextObject



31
32
33
# File 'lib/temporalio/worker/activity_executor/fiber.rb', line 31

def activity_context
  ::Fiber[:temporal_activity_context]
end

#execute_activity(_defn) ⇒ Object



26
27
28
# File 'lib/temporalio/worker/activity_executor/fiber.rb', line 26

def execute_activity(_defn, &)
  ::Fiber.schedule(&)
end

#initialize_activity(defn) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/temporalio/worker/activity_executor/fiber.rb', line 17

def initialize_activity(defn)
  # If there is not a current scheduler, we're going to preemptively
  # fail the registration
  return unless ::Fiber.current_scheduler.nil?

  raise ArgumentError, "Activity '#{defn.name}' wants a fiber executor but no current fiber scheduler"
end

#set_activity_context(defn, context) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/temporalio/worker/activity_executor/fiber.rb', line 36

def set_activity_context(defn, context)
  ::Fiber[:temporal_activity_context] = context
  # If they have opted in to raising on cancel, wire that up
  return unless defn.cancel_raise

  fiber = ::Fiber.current
  context&.cancellation&.add_cancel_callback do
    fiber.raise(Error::CanceledError.new('Activity canceled'))
  end
end