Class: Temporalio::Activity::Definition
- Inherits:
-
Object
- Object
- Temporalio::Activity::Definition
- Defined in:
- lib/temporalio/activity/definition.rb
Overview
Definition of an activity. Activities are usually classes/instances that extend Temporalio::Activity, but definitions can also be manually created with a proc/block.
Instance Attribute Summary collapse
-
#cancel_raise ⇒ Boolean
readonly
Whether to raise in thread/fiber on cancellation.
-
#executor ⇒ Symbol
readonly
Name of the executor.
-
#name ⇒ String, Symbol
readonly
Name of the activity.
-
#proc ⇒ Proc
readonly
Proc for the activity.
Class Method Summary collapse
-
.from_activity(activity) ⇒ Object
Obtain a definition representing the given activity, which can be a class, instance, or definition.
Instance Method Summary collapse
-
#initialize(name:, proc: nil, executor: :default, cancel_raise: true) { ... } ⇒ Definition
constructor
Manually create activity definition.
Constructor Details
#initialize(name:, proc: nil, executor: :default, cancel_raise: true) { ... } ⇒ Definition
Manually create activity definition. Most users will use an instance/class of Temporalio::Activity.
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/temporalio/activity/definition.rb', line 62 def initialize(name:, proc: nil, executor: :default, cancel_raise: true, &block) @name = name if proc.nil? raise ArgumentError, 'Must give proc or block' unless block_given? proc = block elsif block_given? raise ArgumentError, 'Cannot give proc and block' end @proc = proc @executor = executor @cancel_raise = cancel_raise end |
Instance Attribute Details
#cancel_raise ⇒ Boolean (readonly)
Returns Whether to raise in thread/fiber on cancellation. Default is ‘true`.
18 19 20 |
# File 'lib/temporalio/activity/definition.rb', line 18 def cancel_raise @cancel_raise end |
#executor ⇒ Symbol (readonly)
Returns Name of the executor. Default is ‘:default`.
15 16 17 |
# File 'lib/temporalio/activity/definition.rb', line 15 def executor @executor end |
#name ⇒ String, Symbol (readonly)
Returns Name of the activity.
9 10 11 |
# File 'lib/temporalio/activity/definition.rb', line 9 def name @name end |
#proc ⇒ Proc (readonly)
Returns Proc for the activity.
12 13 14 |
# File 'lib/temporalio/activity/definition.rb', line 12 def proc @proc end |
Class Method Details
.from_activity(activity) ⇒ Object
Obtain a definition representing the given activity, which can be a class, instance, or definition.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/temporalio/activity/definition.rb', line 24 def self.from_activity(activity) # Class means create each time, instance means just call, definition # does nothing special case activity when Class raise ArgumentError, "Class '#{activity}' does not extend Activity" unless activity < Activity details = activity._activity_definition_details new( name: details[:activity_name], executor: details[:activity_executor], cancel_raise: details[:activity_cancel_raise], # Instantiate and call proc: proc { |*args| activity.new.execute(*args) } ) when Activity details = activity.class._activity_definition_details new( name: details[:activity_name], executor: details[:activity_executor], cancel_raise: details[:activity_cancel_raise], # Just call proc: proc { |*args| activity.execute(*args) } ) when Activity::Definition activity else raise ArgumentError, "#{activity} is not an activity class, instance, or definition" end end |