Sha256: 42993be4b7bc10df84d38ee9fece9314f89231da57b7c44efab108e9d864f4e5
Contents?: true
Size: 1.46 KB
Versions: 20
Compression:
Stored size: 1.46 KB
Contents
module CapistranoMulticonfigParallel # class that handles the states of the celluloid worker executing the child process in a fork process class StateMachine include ComposableStateMachine::CallbackRunner attr_accessor :state, :model, :machine, :job, :initial_state, :transitions, :output def initialize(job, actor) @job = job @actor = actor @initial_state = :unstarted @model = generate_model build_machine end def go_to_transition(action) @machine.trigger(action.to_s) end private def build_machine @machine = ComposableStateMachine::MachineWithExternalState.new( @model, method(:state), method(:state=), state: initial_state.to_s, callback_runner: self) end def generate_transitions @transitions = ComposableStateMachine::Transitions.new @transitions end def generate_model ComposableStateMachine.model( transitions: generate_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 def actor_notify_state_change(current_state, event, new_state) @actor.send_msg(CapistranoMulticonfigParallel::TerminalTable.topic, type: 'event', message: "Going from #{current_state} to #{new_state} due to a #{event} event") end end end
Version data entries
20 entries across 20 versions & 1 rubygems