class Orchestrator::Service::TransportHttp

Public Class Methods

new(manager, processor) click to toggle source
# File lib/orchestrator/service/transport_http.rb, line 5
def initialize(manager, processor)
    @manager = manager
    @settings = @manager.settings
    @processor = processor

    # Load http endpoint after module has had a chance to update the config
    config = @processor.config
    config[:tls] ||= @settings.tls
    config[:tokenize] = false
    @server = UV::HttpEndpoint.new @settings.uri, config

    @manager.thread.next_tick do
        # Call connected (we only need to do this once)
        # We may never be connected, this is just to signal that we are ready
        @processor.connected
    end
end

Public Instance Methods

terminate() click to toggle source
# File lib/orchestrator/service/transport_http.rb, line 49
def terminate
    @terminated = true
    @server.close_connection(:after_writing)
end
transmit(cmd) click to toggle source
# File lib/orchestrator/service/transport_http.rb, line 23
def transmit(cmd)
    return if @terminated

    # TODO:: Support multiple simultaneous requests (multiple servers)

    @server.request(cmd[:method], cmd).then(
        proc { |result|
            # Make sure the request information is always available
            result[:request] = cmd
            @processor.buffer(result)
            nil
        },
        proc { |failure|
            # Fail fast (no point waiting for the timeout)
            if @processor.queue.waiting #== cmd
                @processor.__send__(:resp_failure, :failed)
            end

            # TODO:: Log failure with more detail
            nil
        }
    )

    nil
end