Class: RailsWorkflow::ProcessManager

Inherits:
Object
  • Object
show all
Defined in:
app/managers/rails_workflow/process_manager.rb

Overview

By default ProcessManager responsible for building, starting and completing process. In future I am planing to extend it with additional functions - for example to broadcast messages between different processes and other functions. Right now this is very basic manager class.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (ProcessManager) initialize(process = nil)

Returns a new instance of ProcessManager



45
46
47
48
49
50
# File 'app/managers/rails_workflow/process_manager.rb', line 45

def initialize process = nil
  if process
    @process = process
    @template = process.template
  end
end

Instance Attribute Details

- (RailsWorkflow::Process) process

Returns process manager's current process

Returns:



40
41
42
# File 'app/managers/rails_workflow/process_manager.rb', line 40

def process
  @process
end

- (RailsWorkflow::ProcessTemplate) template

Returns template of process manager's current proces.

Returns:



43
44
45
# File 'app/managers/rails_workflow/process_manager.rb', line 43

def template
  @template
end

Class Method Details

+ (RailsWorkflow::Process) build_process(template_id, context)

Returns Built but not yet running process in NOT_STARTED status with created (but not started) independent operations.

Returns:

  • (RailsWorkflow::Process)

    Built but not yet running process in NOT_STARTED status with created (but not started) independent operations.

See Also:



19
20
21
22
# File 'app/managers/rails_workflow/process_manager.rb', line 19

def build_process template_id, context
  template = RailsWorkflow::ProcessTemplate.find template_id
  template.build_process! context
end

+ (RailsWorkflow::Process) start_process(template_id, context)

Returns Running process with IN_PROGRESS status. Independent operations is build and running.

Returns:

  • (RailsWorkflow::Process)

    Running process with IN_PROGRESS status. Independent operations is build and running.

See Also:

  • operations


32
33
34
35
36
# File 'app/managers/rails_workflow/process_manager.rb', line 32

def start_process template_id, context
  process = build_process template_id, context
  process.try(:start)
  process
end

Instance Method Details

- (Object) complete_process

Checks if process can be completed and completes it.

See Also:

  • RailsWorkflow::Processes::DefaultRunner.can_complete?
  • RailsWorkflow::Processes::DefaultRunner.complete


81
82
83
84
85
86
# File 'app/managers/rails_workflow/process_manager.rb', line 81

def complete_process
  if process.can_complete?
    process.complete

  end
end

- (Object) operation_complete(operation)

Every operation informs manager when it's complete or changing it's status. When operation complete, process manager searching for new operations to create or complete process.



71
72
73
74
75
# File 'app/managers/rails_workflow/process_manager.rb', line 71

def operation_complete operation
  process.operation_complete operation

  complete_process
end

- (Object) operation_exception

Processing operation exceptions. In current realization just set process to ERROR status.



63
64
65
# File 'app/managers/rails_workflow/process_manager.rb', line 63

def operation_exception
  process.operation_exception
end

- (Object) start_process

Starts current process



54
55
56
57
58
# File 'app/managers/rails_workflow/process_manager.rb', line 54

def start_process
  process.start
rescue => exception
  RailsWorkflow::Error.create_from exception, parent: process
end