Sha256: 7609003898bab0a96af3a8ec006183f202d8b15ea73484fb70dd6ea2f31a5e8e

Contents?: true

Size: 1.47 KB

Versions: 22

Compression:

Stored size: 1.47 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', new_state: new_state, message: "Going from #{current_state} to #{new_state}  due to a #{event} event")
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
capistrano_multiconfig_parallel-1.3.1 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.3.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.2.9 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.2.8 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.2.7 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.2.6 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.2.5 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.2.4 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.2.3 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.2.2 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.2.1 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.2.0 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.1.9 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.1.8 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.1.7 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.1.6 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.1.5 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.1.4 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.1.3 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb
capistrano_multiconfig_parallel-1.1.2 lib/capistrano_multiconfig_parallel/celluloid/state_machine.rb