Sha256: cf23470b65a1f1ee58dc81904dcf49be45a90f33b4e2dac86fd148494132efa3

Contents?: true

Size: 1.83 KB

Versions: 3

Compression:

Stored size: 1.83 KB

Contents

module Orchestrator
    module Service
        class TransportHttp
            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

            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

            def terminate
                @terminated = true
                @server.close_connection(:after_writing)
            end
        end
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
orchestrator-1.0.3 lib/orchestrator/service/transport_http.rb
orchestrator-1.0.2 lib/orchestrator/service/transport_http.rb
orchestrator-1.0.1 lib/orchestrator/service/transport_http.rb