Class: Temporalio::Worker::ActivityExecutor

Inherits:
Object
  • Object
show all
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

ThreadPool

Defined Under Namespace

Classes: Fiber, ThreadPool

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultsHash<Symbol, ActivityExecutor>

Returns Default set of executors (immutable).

Returns:



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_contextActivity::Context?

Returns Get the current activity context. This is called by users from inside the activity. Implementers must implement this.

Returns:

  • (Activity::Context, nil)

    Get the current activity context. This is called by users from inside the activity. Implementers must implement this.

Raises:

  • (NotImplementedError)


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.

Parameters:

Yields:

  • Block to execute.

Raises:

  • (NotImplementedError)


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.

Parameters:



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.

Parameters:

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/temporalio/worker/activity_executor.rb', line 50

def set_activity_context(defn, context)
  raise NotImplementedError
end