Class: RigidWorkflow::Workflow

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

Parameters:

  • params (Hash) (defaults to: {})

    Initial parameters

Returns:



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.

Parameters:

  • value (Integer)

    The version number

Returns:

  • (Integer)


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.

Parameters:

  • message (String)

    The message to log



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rigid_workflow/workflow.rb', line 40

def log(message, severity: Logger::INFO)
  return if !RigidWorkflow.config.logging? && Rails.env.test?

  @log_index ||= 0
  @log_index += 1

  memo "log_#{@log_index}" do
    puts message unless Rails.env.test?
    log_to_rails(severity, message)
  end
end

#log_to_rails(severity, message) ⇒ Object



52
53
54
# File 'lib/rigid_workflow/workflow.rb', line 52

def log_to_rails(severity, message)
  Rails.logger.log(severity, "[#{@workflow_run.id.to_s[0..12]}] #{message}")
end

#runObject

The main workflow logic. Must be implemented by subclasses.

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/rigid_workflow/workflow.rb', line 34

def run
  raise NotImplementedError, "Subclass must implement #run"
end