Class: RigidWorkflow::Activity
- Inherits:
-
Object
- Object
- RigidWorkflow::Activity
- Defined in:
- lib/rigid_workflow/activity.rb
Overview
Base class for all activities. Activities represent a single, idempotent unit of work within a workflow.
Class Method Summary collapse
-
.force_async(value) ⇒ Object
Forces all instances of this activity to run asynchronously.
-
.force_async? ⇒ Boolean
Whether this activity is forced to run asynchronously.
Instance Method Summary collapse
-
#compensate ⇒ Object
Called during compensation to undo this activity’s side effects.
-
#initialize(step) ⇒ Activity
constructor
private
A new instance of Activity.
-
#log(message, severity: Logger::INFO) ⇒ Object
Logs a message associated with this activity execution.
-
#perform(**args) ⇒ Object
The main activity logic.
Constructor Details
#initialize(step) ⇒ 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.
22 23 24 25 26 |
# File 'lib/rigid_workflow/activity.rb', line 22 def initialize(step) @workflow_run_id = step.rigid_workflow_run_id @step_name = step.step_name @step = step end |
Class Method Details
.force_async(value) ⇒ Object
Forces all instances of this activity to run asynchronously.
11 12 13 14 |
# File 'lib/rigid_workflow/activity.rb', line 11 def self.force_async(value) self.configs = self.configs.merge(force_async: value) self end |
.force_async? ⇒ Boolean
Returns Whether this activity is forced to run asynchronously.
17 18 19 |
# File 'lib/rigid_workflow/activity.rb', line 17 def self.force_async? self.configs[:force_async] == true end |
Instance Method Details
#compensate ⇒ Object
Called during compensation to undo this activity’s side effects. Override in subclasses. Default does nothing.
51 52 |
# File 'lib/rigid_workflow/activity.rb', line 51 def compensate end |
#log(message, severity: Logger::INFO) ⇒ Object
Logs a message associated with this activity execution.
38 39 40 41 42 43 44 45 46 |
# File 'lib/rigid_workflow/activity.rb', line 38 def log(, severity: Logger::INFO) return if !RigidWorkflow.config.logging? && Rails.env.test? puts unless Rails.env.test? Rails.logger.log( severity, "[#{@workflow_run_id.to_s[0..12]}][#{@step_name}] #{}" ) end |
#perform(**args) ⇒ Object
The main activity logic. Must be implemented by subclasses.
31 32 33 34 |
# File 'lib/rigid_workflow/activity.rb', line 31 def perform(**args) return if Rails.env.test? && !RigidWorkflow.config.logging? raise NotImplementedError, "Subclass must implement #perform" end |