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

Version Path
capistrano_multiconfig_parallel-0.18.1 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.18.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.17.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.16.2 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.16.1 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.16.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.15.6 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.15.5 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.15.4 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.15.3 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.15.2 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.15.1 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.15.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.14.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.13.2 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.13.1 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.13.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.12.9 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.12.8 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.12.7 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb