Class: CapistranoMulticonfigParallel::StateMachine

Inherits:
Object
  • Object
show all
Includes:
ComposableStateMachine::CallbackRunner
Defined in:
lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb

Overview

class that handles the states of the celluloid worker executing the child process in a fork process

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job, actor) ⇒ StateMachine

Returns a new instance of StateMachine.



7
8
9
10
11
12
# File 'lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb', line 7

def initialize(job, actor)
  @job = job
  @actor = actor
  @initial_state = @job.status
  machine
end

Instance Attribute Details

#actorObject

Returns the value of attribute actor.



5
6
7
# File 'lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb', line 5

def actor
  @actor
end

#initial_stateObject

Returns the value of attribute initial_state.



5
6
7
# File 'lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb', line 5

def initial_state
  @initial_state
end

#jobObject

Returns the value of attribute job.



5
6
7
# File 'lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb', line 5

def job
  @job
end

#stateObject

Returns the value of attribute state.



5
6
7
# File 'lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb', line 5

def state
  @state
end

Instance Method Details

#go_to_transition(action, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb', line 14

def go_to_transition(action, options = {})
  return if @job.status.to_s.downcase == 'dead'
  transitions.on(action, state.to_s => action)
  @job.status = action
  if options[:bundler]
    @job.bundler_status = action
    actor_notify_state_change(state, "preparing_app_bundle_install", action)
  else
    @job.bundler_status = nil
    machine.trigger(action)
  end
end

#machineObject



27
28
29
30
31
# File 'lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb', line 27

def machine
  @machine ||= ComposableStateMachine::MachineWithExternalState.new(
  model, method(:state), method(:state=), state: @initial_state.to_s, callback_runner: self)
  @machine
end

#modelObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb', line 38

def model
  ComposableStateMachine.model(
  transitions: transitions,
  behaviors: {
    enter: {
      any: proc do |current_state, event, new_state|
        actor_notify_state_change(current_state, event, new_state)
      end
    }
  },
  initial_state: @initial_state
  )
end

#transitionsObject



33
34
35
36
# File 'lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb', line 33

def transitions
  @transitions ||= ComposableStateMachine::Transitions.new
  @transitions
end