Sha256: b62b85f15758c13f750bb1b5348007006a22369d147877203aea7ca2f34237c7

Contents?: true

Size: 1.45 KB

Versions: 60

Compression:

Stored size: 1.45 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)
      @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

60 entries across 60 versions & 1 rubygems

Version Path
capistrano_multiconfig_parallel-0.29.1 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.29.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.28.5 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.28.4 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.28.3 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.28.2 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.28.1 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.28.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.27.2 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.27.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.26.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.25.1 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.25.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.24.1 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.24.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.23.4 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.23.3 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.23.2 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.23.1 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-0.23.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb