class CapistranoMulticonfigParallel::StateMachine

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

Attributes

actor[RW]
initial_state[RW]
job[RW]
state[RW]

Public Class Methods

new(job, actor) click to toggle source
# 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

Public Instance Methods

go_to_transition(action, options = {}) click to toggle source
# 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
machine() click to toggle source
# 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
model() click to toggle source
# 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
transitions() click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb, line 33
def transitions
  @transitions ||= ComposableStateMachine::Transitions.new
  @transitions
end

Private Instance Methods

actor_notify_state_change(current_state, event, new_state) click to toggle source
# File lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb, line 54
def actor_notify_state_change(current_state, event, new_state)
  return unless @actor.alive?
  @actor.log_to_file("statemachine #{@job.id} triest to transition from #{@current_state} to  #{new_state} for event #{event}")
  @actor.async.send_msg(CapistranoMulticonfigParallel::TerminalTable.topic, type: 'event', new_state: new_state , current_state: current_state, event: event, message: "Going from #{current_state} to #{new_state}  due to a #{event} event")
end