Class: Shikibu::Activity
- Inherits:
-
Object
- Object
- Shikibu::Activity
- Defined in:
- lib/shikibu/activity.rb
Overview
Standalone activity definition Use this for reusable activities that can be shared across workflows
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#retry_policy ⇒ Object
readonly
Returns the value of attribute retry_policy.
Instance Method Summary collapse
-
#call(ctx, **kwargs) ⇒ Object
Execute the activity within a workflow context.
-
#initialize(name, retry_policy: nil, &block) ⇒ Activity
constructor
Create a new activity.
Constructor Details
#initialize(name, retry_policy: nil, &block) ⇒ Activity
Create a new activity
22 23 24 25 26 |
# File 'lib/shikibu/activity.rb', line 22 def initialize(name, retry_policy: nil, &block) @name = name.to_s @retry_policy = retry_policy || RetryPolicy.default @block = block end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/shikibu/activity.rb', line 16 def name @name end |
#retry_policy ⇒ Object (readonly)
Returns the value of attribute retry_policy.
16 17 18 |
# File 'lib/shikibu/activity.rb', line 16 def retry_policy @retry_policy end |
Instance Method Details
#call(ctx, **kwargs) ⇒ Object
Execute the activity within a workflow context
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/shikibu/activity.rb', line 32 def call(ctx, **kwargs) activity_id = ctx.generate_activity_id(@name) ctx.current_activity_id = activity_id # Check for cached result during replay if ctx. && ctx.cached_result?(activity_id) cached = ctx.get_cached_result(activity_id) return cached[:result] if cached[:event_type] == EventType::ACTIVITY_COMPLETED # Re-raise cached error raise reconstruct_error(cached) end # Execute with retry execute_with_retry(ctx, activity_id, kwargs) ensure ctx.current_activity_id = nil end |