Class: Temporalio::Worker::ActivityExecutor::Fiber
- Inherits:
-
Object
- Object
- Temporalio::Worker::ActivityExecutor::Fiber
- Defined in:
- lib/temporalio/worker/activity_executor/fiber.rb
Overview
Activity executor for scheduling activites as fibers.
Class Method Summary collapse
-
.default ⇒ Fiber
Default/shared Fiber executor instance.
Instance Method Summary collapse
- #activity_context ⇒ Object
- #execute_activity(_defn) ⇒ Object
- #initialize_activity(defn) ⇒ Object
- #set_activity_context(defn, context) ⇒ Object
Class Method Details
.default ⇒ Fiber
Returns 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_context ⇒ Object
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 |