class RailsWorkflow::ProcessRunner

ProcessRunner

This module contains logic of process start, stop, cancel etc.

Attributes

process[R]

Public Class Methods

new(process) click to toggle source
# File lib/rails_workflow/process_runner.rb, line 15
def initialize(process)
  @process = process
end

Public Instance Methods

completable?() click to toggle source

Process can be completed if all sync operations is complete

# File lib/rails_workflow/process_runner.rb, line 28
def completable?
  uncompleted? && workflow_errors.unresolved.size.zero?
end
complete() click to toggle source

TODO: change to try_complete

# File lib/rails_workflow/process_runner.rb, line 37
def complete
  return unless completable?

  process.complete
  complete_parent_operation
end
complete_parent_operation() click to toggle source
# File lib/rails_workflow/process_runner.rb, line 32
def complete_parent_operation
  parent_operation.complete if parent_operation.present?
end
operation_completed(operation) click to toggle source
# File lib/rails_workflow/process_runner.rb, line 44
def operation_completed(operation)
  build_new_operations(operation)
  complete
end
start() click to toggle source
# File lib/rails_workflow/process_runner.rb, line 19
def start
  return unless can_start?

  process.update_attribute(:status, Status::IN_PROGRESS)
  # TODO: replace with OperationRunner
  operation_runner.start(operations.where(status: Status::NOT_STARTED))
end

Private Instance Methods

build_new_operations(operation) click to toggle source
# File lib/rails_workflow/process_runner.rb, line 51
def build_new_operations(operation)
  new_operations = dependency_resolver.build_new_operations(operation)

  return if new_operations.blank?

  operations.concat(new_operations)
  operation_runner.start(new_operations)
end
config() click to toggle source
# File lib/rails_workflow/process_runner.rb, line 68
def config
  RailsWorkflow.config
end
dependency_resolver() click to toggle source
# File lib/rails_workflow/process_runner.rb, line 64
def dependency_resolver
  @dependency_resolver ||= config.dependency_resolver.new(process)
end
operation_runner() click to toggle source
# File lib/rails_workflow/process_runner.rb, line 60
def operation_runner
  config.operation_runner
end