Sha256: ae06f35136f68790b112724192f02ba62a359890d68f279db07d3bdc070280b4
Contents?: true
Size: 1.5 KB
Versions: 10
Compression:
Stored size: 1.5 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 :job, :actor, :initial_state, :state def initialize(job, actor) @job = job @actor = actor @initial_state = @job.status machine end def go_to_transition(action) transitions.on(action, state.to_s => action) @job.status = action machine.trigger(action) end def machine @machine ||= ComposableStateMachine::MachineWithExternalState.new( model, method(:state), method(:state=), state: @initial_state.to_s, callback_runner: self) @machine end def transitions @transitions ||= ComposableStateMachine::Transitions.new @transitions end 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 private def actor_notify_state_change(current_state, event, new_state) return unless @actor.alive? @actor.send_msg(CapistranoMulticonfigParallel::TerminalTable.topic, type: 'event', new_state: new_state, message: "Going from #{current_state} to #{new_state} due to a #{event} event") end end end
Version data entries
10 entries across 10 versions & 1 rubygems