Class: RigidWorkflow::Workflow
- Inherits:
-
Object
- Object
- RigidWorkflow::Workflow
- Extended by:
- Forwardable
- Defined in:
- lib/rigid_workflow/workflow.rb
Overview
Base class for all workflow definitions. Subclasses must implement the #run method.
Class Method Summary collapse
-
.start!(params = {}) ⇒ RigidWorkflow::Run
Starts a workflow run for this class.
-
.version(value) ⇒ Integer
Sets the version for this workflow class.
Instance Method Summary collapse
-
#initialize(workflow_run) ⇒ Workflow
constructor
private
A new instance of Workflow.
-
#log(message, severity: Logger::INFO) ⇒ Object
Logs a message that is persisted and associated with the workflow run.
- #log_to_rails(severity, message) ⇒ Object
-
#run ⇒ Object
The main workflow logic.
Constructor Details
#initialize(workflow_run) ⇒ Workflow
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 Workflow.
26 27 28 29 30 31 |
# File 'lib/rigid_workflow/workflow.rb', line 26 def initialize(workflow_run) @workflow_run = workflow_run @run_version = workflow_run.version @runner = WorkflowRunner.new(workflow_run) @params = workflow_run.params.with_indifferent_access end |
Class Method Details
.start!(params = {}) ⇒ RigidWorkflow::Run
Starts a workflow run for this class
21 22 23 |
# File 'lib/rigid_workflow/workflow.rb', line 21 def self.start!(params = {}) RigidWorkflow::Orchestrator.start(self, params) end |
.version(value) ⇒ Integer
Sets the version for this workflow class.
14 15 16 |
# File 'lib/rigid_workflow/workflow.rb', line 14 def self.version(value) self.workflow_version = value end |
Instance Method Details
#log(message, severity: Logger::INFO) ⇒ Object
Logs a message that is persisted and associated with the workflow run.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rigid_workflow/workflow.rb', line 40 def log(, severity: Logger::INFO) return if !RigidWorkflow.config.logging? && Rails.env.test? @log_index ||= 0 @log_index += 1 memo "log_#{@log_index}" do puts unless Rails.env.test? log_to_rails(severity, ) end end |
#log_to_rails(severity, message) ⇒ Object
52 53 54 |
# File 'lib/rigid_workflow/workflow.rb', line 52 def log_to_rails(severity, ) Rails.logger.log(severity, "[#{@workflow_run.id.to_s[0..12]}] #{}") end |
#run ⇒ Object
The main workflow logic. Must be implemented by subclasses.
34 35 36 |
# File 'lib/rigid_workflow/workflow.rb', line 34 def run raise NotImplementedError, "Subclass must implement #run" end |