Class: Temporalio::Activity
- Inherits:
-
Object
- Object
- Temporalio::Activity
- Defined in:
- lib/temporalio/activity.rb,
lib/temporalio/activity/info.rb,
lib/temporalio/activity/context.rb,
lib/temporalio/activity/definition.rb,
lib/temporalio/activity/complete_async_error.rb
Overview
Base class for all activities.
Activities can be given to a worker as instances of this class, which will call execute on the same instance for each execution, or given to the worker as the class itself which instantiates the activity for each execution.
All activities must implement #execute. Inside execute, Context.current can be used to access the current context to get information, issue heartbeats, etc.
By default, the activity is named as its unqualified class name. This can be customized with Activity.activity_name.
By default, the activity uses the ‘:default` executor which is usually the thread-pool based executor. This can be customized with Activity.activity_executor.
By default, upon cancellation Thread.raise or Fiber.raise is called with a Error::CanceledError. This can be disabled by passing ‘false` to Activity.activity_cancel_raise.
See documentation for more detail on activities.
Defined Under Namespace
Classes: CompleteAsyncError, Context, Definition, Info
Class Method Summary collapse
-
.activity_cancel_raise(cancel_raise) ⇒ Object
Override whether the activity uses Thread/Fiber raise for cancellation which is defaulted to true.
-
.activity_executor(executor_name) ⇒ Object
Override the activity executor which is defaulted to ‘:default`.
-
.activity_name(name) ⇒ Object
Override the activity name which is defaulted to the unqualified class name.
Instance Method Summary collapse
-
#execute(*args) ⇒ Object
Implementation of the activity.
Class Method Details
.activity_cancel_raise(cancel_raise) ⇒ Object
Override whether the activity uses Thread/Fiber raise for cancellation which is defaulted to true.
48 49 50 51 52 |
# File 'lib/temporalio/activity.rb', line 48 def self.activity_cancel_raise(cancel_raise) raise ArgumentError, 'Must be a boolean' unless cancel_raise.is_a?(TrueClass) || cancel_raise.is_a?(FalseClass) @activity_cancel_raise = cancel_raise end |
.activity_executor(executor_name) ⇒ Object
Override the activity executor which is defaulted to ‘:default`.
39 40 41 42 43 |
# File 'lib/temporalio/activity.rb', line 39 def self.activity_executor(executor_name) raise ArgumentError, 'Executor name must be a symbol' unless executor_name.is_a?(Symbol) @activity_executor = executor_name end |
.activity_name(name) ⇒ Object
Override the activity name which is defaulted to the unqualified class name.
30 31 32 33 34 |
# File 'lib/temporalio/activity.rb', line 30 def self.activity_name(name) raise ArgumentError, 'Activity name must be a symbol or string' if !name.is_a?(Symbol) && !name.is_a?(String) @activity_name = name.to_s end |
Instance Method Details
#execute(*args) ⇒ Object
Implementation of the activity. The arguments should be positional and this should return the value on success or raise an error on failure.
65 66 67 |
# File 'lib/temporalio/activity.rb', line 65 def execute(*args) raise NotImplementedError, 'Activity did not implement "execute"' end |