Sha256: 6de9e85de2a8455dffc7bf070269630604e8b301331712ef2b63e66ad0a29954

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

class Freddy
  class RequestManager

    def initialize(requests, logger)
      @requests, @logger = requests, logger
    end

    def start
      @timeout_thread = Thread.new do
        while true do
          clear_timeouts Time.now
          sleep 0.05
        end
      end
    end

    def no_route(correlation_id)
      if request = @requests[correlation_id]
        @requests.delete correlation_id
        request[:callback].call({error: 'Specified queue does not exist'}, nil)
      end
    end

    private

    def clear_timeouts(now)
      @requests.each do |key, value|
        timeout(key, value) if now > value[:timeout]
      end
    end

    def timeout(correlation_id, request)
      @requests.delete correlation_id

      @logger.warn "Request timed out waiting response from #{request[:destination]}, correlation id #{correlation_id}"
      Utils.notify 'RequestTimeout', "Request timed out waiting for response from #{request[:destination]}", {
        correlation_id: correlation_id,
        destination: request[:destination],
        timeout: request[:timeout]
      }

      request[:callback].call({error: 'RequestTimeout', message: 'Timed out waiting for response'}, nil)
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
freddy-jruby-0.4.9 lib/freddy/request_manager.rb
freddy-0.4.9 lib/freddy/request_manager.rb
freddy-0.4.8 lib/freddy/request_manager.rb
freddy-0.4.7 lib/freddy/request_manager.rb
freddy-0.4.6 lib/freddy/request_manager.rb