Class: Temporalio::Activity Abstract
- Inherits:
-
Object
- Object
- Temporalio::Activity
- Defined in:
- lib/temporalio/activity.rb,
lib/temporalio/activity/info.rb,
lib/temporalio/activity/context.rb
Overview
This is an abstract superclass for implementing activities.
Temporal SDK users are expected to subclass it and implement the #execute method by adding their desired business logic.
Defined Under Namespace
Class Method Summary collapse
- ._name ⇒ Object private
- ._shielded ⇒ Object private
-
.activity_name(new_name) ⇒ Object
Specify a custom name to be used for this activity.
-
.shielded! ⇒ Object
Mark the activity as shielded from cancellations.
Instance Method Summary collapse
-
#execute(*_args) ⇒ Object
This is the main body of your activity’s implementation.
-
#initialize(context) ⇒ Activity
constructor
private
A new instance of Activity.
Constructor Details
#initialize(context) ⇒ Activity
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Activity.
64 65 66 |
# File 'lib/temporalio/activity.rb', line 64 def initialize(context) @context = context end |
Class Method Details
._name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
54 55 56 |
# File 'lib/temporalio/activity.rb', line 54 def self._name @activity_name || name || '' end |
._shielded ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 60 61 |
# File 'lib/temporalio/activity.rb', line 59 def self._shielded @shielded || false end |
.activity_name(new_name) ⇒ Object
Specify a custom name to be used for this activity.
By default a full class (with any namespace modules/classes) name will be used.
30 31 32 |
# File 'lib/temporalio/activity.rb', line 30 def self.activity_name(new_name) @activity_name = new_name end |
.shielded! ⇒ Object
Mark the activity as shielded from cancellations.
Activity cancellations are implemented using the ‘Thread#raise`, which can unsafely terminate your implementation. To disable this behaviour make sure to mark critical activities as `shielded!`. For shielding a part of your activity consider using Temporalio::Activity::Context#shield.
49 50 51 |
# File 'lib/temporalio/activity.rb', line 49 def self.shielded! @shielded = true end |
Instance Method Details
#execute(*_args) ⇒ Object
This is the main body of your activity’s implementation.
When implementing this method, you can use as many positional arguments as needed, which will get converted based on the activity invocation in your workflow.
Inside of this method you have access to activity’s context using the ‘activity` method. Check out Context for more information on how to use it.
75 76 77 |
# File 'lib/temporalio/activity.rb', line 75 def execute(*_args) raise NoMethodError, 'must implement #execute' end |