Sha256: 97dc503fd408a440be0221018f20b40c5098d35c5a818fb63124122f9e7132cc

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

module Eye::Controller::Commands

  # Main method, answer for the client command
  def command(cmd, *args)
    debug "client command: #{cmd} #{args * ', '}"

    start_at = Time.now
    cmd = cmd.to_sym
    
    res = case cmd 
      when :start, :stop, :restart, :unmonitor, :monitor
        send_command(cmd, *args)
      when :delete
        exclusive{ send_command(cmd, *args) }
      when :signal
        signal(*args)
      when :break_chain
        break_chain(*args)
      when :load
        exclusive{ load(*args) }
      when :info
        info_string(*args)
      when :xinfo
        info_string_debug(*args)
      when :oinfo
        info_string_short
      when :history
        history_string(*args)
      when :quit
        quit
      when :check
        check(*args)
      when :explain
        explain(*args)
      when :match
        match(*args)
      when :ping
        :pong
      when :logger_dev
        Eye::Logger.dev

      # object commands, for api
      when :raw_info
        info_data(*args)
      when :raw_history
        history_data(*args)

      else
        :unknown_command
    end   

    GC.start
    info "client command: #{cmd} #{args * ', '} (#{Time.now - start_at}s)"

    res  
  end

private

  def quit
    info 'exiting...'
    delete
    sleep 1
    Eye::System.send_signal($$) # soft terminate
    sleep 2
    Eye::System.send_signal($$, 9)
  end

  def delete
    send_command(:delete)
  end

end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
reel-eye-0.3.1 lib/eye/controller/commands.rb
eye-0.3.1 lib/eye/controller/commands.rb
eye-0.3 lib/eye/controller/commands.rb
eye-0.2.4 lib/eye/controller/commands.rb