Class: RailsWorkflow::ProcessRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_workflow/process_runner.rb

Overview

ProcessRunner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(process) ⇒ ProcessRunner

Returns a new instance of ProcessRunner.



15
16
17
# File 'lib/rails_workflow/process_runner.rb', line 15

def initialize(process)
  @process = process
end

Instance Attribute Details

#processObject (readonly)

Returns the value of attribute process.



10
11
12
# File 'lib/rails_workflow/process_runner.rb', line 10

def process
  @process
end

Instance Method Details

#completable?Boolean

Process can be completed if all sync operations is complete

Returns:

  • (Boolean)


28
29
30
# File 'lib/rails_workflow/process_runner.rb', line 28

def completable?
  uncompleted? && workflow_errors.unresolved.size.zero?
end

#completeObject

TODO: change to try_complete



37
38
39
40
41
42
# File 'lib/rails_workflow/process_runner.rb', line 37

def complete
  return unless completable?

  process.complete
  complete_parent_operation
end

#complete_parent_operationObject



32
33
34
# File 'lib/rails_workflow/process_runner.rb', line 32

def complete_parent_operation
  parent_operation.complete if parent_operation.present?
end

#operation_completed(operation) ⇒ Object



44
45
46
47
# File 'lib/rails_workflow/process_runner.rb', line 44

def operation_completed(operation)
  build_new_operations(operation)
  complete
end

#startObject



19
20
21
22
23
24
25
# 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