Sha256: 839ed4a3449f17958353223239d7959db5760f3cf1bc686e659b47f64c1830e9

Contents?: true

Size: 922 Bytes

Versions: 7

Compression:

Stored size: 922 Bytes

Contents

require 'socket'

module Kirk
  class Server::RedeployClient
    def self.redeploy(socket, path, &blk)
      new(socket).redeploy(path, &blk)
    end

    def initialize(unix_socket_path)
      @unix_socket, @unix_socket_path = nil, unix_socket_path
    end

    def redeploy(path, &blk)
      connect
      @unix_socket.write "REDEPLOY #{path}\n"
      handle_response(&blk)
    ensure
      disconnect
    end

  private

    def connect
      @unix_socket = UNIXSocket.new(@unix_socket_path)
    end

    def disconnect
      @unix_socket.close
    end

    def handle_response(&blk)
      yield "Waiting for response..." if block_given?

      while line = @unix_socket.gets
        msg = case line
        when /^INFO (.*)$/  then $1
        when /^ERROR (.*)$/ then "[ERROR] #{$1}"
        else "[ERROR] Received unknown message: `#{line}`"
        end

        yield msg if block_given?
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kirk-0.2.0.beta.7-java lib/kirk/server/redeploy_client.rb
kirk-0.2.0.beta.6-java lib/kirk/server/redeploy_client.rb
kirk-0.2.0.beta.5-java lib/kirk/server/redeploy_client.rb
kirk-0.2.0.beta.4-java lib/kirk/server/redeploy_client.rb
kirk-0.2.0.beta.3-java lib/kirk/server/redeploy_client.rb
kirk-0.2.0.beta.2-java lib/kirk/server/redeploy_client.rb
kirk-0.2.0.beta.1-java lib/kirk/server/redeploy_client.rb