Class: Temporalio::Worker::ActivityExecutor
- Inherits:
-
Object
- Object
- Temporalio::Worker::ActivityExecutor
- Defined in:
- lib/temporalio/worker/activity_executor.rb,
lib/temporalio/worker/activity_executor/fiber.rb,
lib/temporalio/worker/activity_executor/thread_pool.rb
Overview
Base class to be extended by activity executor implementations. Most users will not use this, but rather keep with the two defaults of thread pool and fiber executors.
Direct Known Subclasses
Defined Under Namespace
Classes: Fiber, ThreadPool
Class Method Summary collapse
-
.defaults ⇒ Hash<Symbol, ActivityExecutor>
Default set of executors (immutable).
Instance Method Summary collapse
-
#activity_context ⇒ Activity::Context?
Get the current activity context.
-
#execute_activity(defn) { ... } ⇒ Object
Execute the given block in the executor.
-
#initialize_activity(defn) ⇒ Object
Initialize an activity.
-
#set_activity_context(defn, context) ⇒ Object
Set the current activity context (or unset if nil).
Class Method Details
.defaults ⇒ Hash<Symbol, ActivityExecutor>
Returns Default set of executors (immutable).
12 13 14 15 16 17 18 |
# File 'lib/temporalio/worker/activity_executor.rb', line 12 def self.defaults @defaults ||= { default: ThreadPool.default, thread_pool: ThreadPool.default, fiber: Fiber.default }.freeze end |
Instance Method Details
#activity_context ⇒ Activity::Context?
Returns Get the current activity context. This is called by users from inside the activity. Implementers must implement this.
40 41 42 |
# File 'lib/temporalio/worker/activity_executor.rb', line 40 def activity_context raise NotImplementedError end |
#execute_activity(defn) { ... } ⇒ Object
Execute the given block in the executor. The block is built to never raise and need no arguments. Implementers must implement this.
34 35 36 |
# File 'lib/temporalio/worker/activity_executor.rb', line 34 def execute_activity(defn, &) raise NotImplementedError end |
#initialize_activity(defn) ⇒ Object
Initialize an activity. This is called on worker initialize for every activity that will use this executor. This allows executor implementations to do eager validation based on the definition. This does not have to be implemented and the default is a no-op.
25 26 27 |
# File 'lib/temporalio/worker/activity_executor.rb', line 25 def initialize_activity(defn) # Default no-op end |
#set_activity_context(defn, context) ⇒ Object
Set the current activity context (or unset if nil). This is called by the system from within the block given to #execute_activity with a context before user code is executed and with nil after user code is complete. Implementers must implement this.
50 51 52 |
# File 'lib/temporalio/worker/activity_executor.rb', line 50 def set_activity_context(defn, context) raise NotImplementedError end |