faraday_persistent_excon 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 60b6db2679ae22d227327fe73885fe687bdfd026
         | 
| 4 | 
            +
              data.tar.gz: 8a40b8f2860d2cabf0fdb4a123985a5bf5a8d1c9
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 7183a66296ca9d76e6a8968fc4d9627a03c1450e70363f4d18266603ea7017cb797de4dd4e1e97615195f2302695701d689e3aca10185907e492b283b889dc23
         | 
| 7 | 
            +
              data.tar.gz: 86a3e03601d0657125d31656a89460f6a448fd66a14b1e888108ae1836e5a06ed7bbed56a5c72307689b5bec419ab1f577a5e94b5ee1281a3587f36f6c0b1aff
         | 
    
        data/README.md
    CHANGED
    
    | @@ -33,7 +33,7 @@ Excon.defaults[:tcp_nodelay] = true | |
| 33 33 | 
             
            Faraday.default_adapter = :persistent_excon
         | 
| 34 34 | 
             
            FaradayPersistentExcon.connection_pools = {
         | 
| 35 35 | 
             
              'https://search.example.com' => { size: 5 },
         | 
| 36 | 
            -
              'http://localhost:9200' => { size: 10, timeout: 2 }
         | 
| 36 | 
            +
              'http://localhost:9200' => { size: 10, timeout: 2, idle_timeout: 300 }
         | 
| 37 37 | 
             
            }
         | 
| 38 38 | 
             
            ```
         | 
| 39 39 |  | 
| @@ -9,6 +9,7 @@ require 'faraday_persistent_excon/perform_request' | |
| 9 9 | 
             
            require 'faraday_persistent_excon/adapter'
         | 
| 10 10 | 
             
            require 'faraday_persistent_excon/request_options'
         | 
| 11 11 | 
             
            require 'faraday_persistent_excon/connection_pools'
         | 
| 12 | 
            +
            require 'faraday_persistent_excon/connection'
         | 
| 12 13 |  | 
| 13 14 | 
             
            module FaradayPersistentExcon
         | 
| 14 15 | 
             
              class << self
         | 
| @@ -17,6 +18,7 @@ module FaradayPersistentExcon | |
| 17 18 | 
             
                attr_accessor :connection_pools
         | 
| 18 19 | 
             
                attr_accessor :idempotent_methods
         | 
| 19 20 | 
             
                attr_accessor :retry_idempotent_methods
         | 
| 21 | 
            +
                attr_accessor :idle_timeout
         | 
| 20 22 | 
             
              end
         | 
| 21 23 |  | 
| 22 24 | 
             
              self.excon_options = {}
         | 
| @@ -24,6 +26,7 @@ module FaradayPersistentExcon | |
| 24 26 | 
             
              self.connection_pools = {}
         | 
| 25 27 | 
             
              self.idempotent_methods = %w[GET HEAD PUT DELETE OPTIONS TRACE]
         | 
| 26 28 | 
             
              self.retry_idempotent_methods = true
         | 
| 29 | 
            +
              self.idle_timeout = 60
         | 
| 27 30 | 
             
            end
         | 
| 28 31 |  | 
| 29 32 | 
             
            Faraday::Adapter.register_middleware persistent_excon: ->{ FaradayPersistentExcon::Adapter }
         | 
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            module FaradayPersistentExcon
         | 
| 2 | 
            +
              class Connection
         | 
| 3 | 
            +
                attr_accessor :excon
         | 
| 4 | 
            +
                attr_accessor :last_use
         | 
| 5 | 
            +
                attr_accessor :idle_timeout
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def initialize(excon:, idle_timeout:)
         | 
| 8 | 
            +
                  @excon = excon
         | 
| 9 | 
            +
                  @idle_timeout = idle_timeout
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def reset
         | 
| 13 | 
            +
                  excon.reset
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                def expired?
         | 
| 17 | 
            +
                  return false if last_use.nil?
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  Time.now.utc - last_use > idle_timeout
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def used!
         | 
| 23 | 
            +
                  self.last_use = Time.now.utc
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
            end
         | 
| @@ -10,7 +10,14 @@ module FaradayPersistentExcon | |
| 10 10 | 
             
                    pool = self.connection_pool_for(url)
         | 
| 11 11 |  | 
| 12 12 | 
             
                    if pool
         | 
| 13 | 
            -
                      pool.with | 
| 13 | 
            +
                      pool.with do |conn|
         | 
| 14 | 
            +
                        begin
         | 
| 15 | 
            +
                          conn.reset if conn.expired?
         | 
| 16 | 
            +
                          block.call(conn.excon)
         | 
| 17 | 
            +
                        ensure
         | 
| 18 | 
            +
                          conn.used!
         | 
| 19 | 
            +
                        end
         | 
| 20 | 
            +
                      end
         | 
| 14 21 | 
             
                    else
         | 
| 15 22 | 
             
                      # No pool configured.  Use normal connection
         | 
| 16 23 | 
             
                      block.call(::Excon.new(url, persistent: false))
         | 
| @@ -23,7 +30,14 @@ module FaradayPersistentExcon | |
| 23 30 | 
             
                    if config
         | 
| 24 31 | 
             
                      self.__pools.fetch_or_store(url) do
         | 
| 25 32 | 
             
                        ::ConnectionPool.new(config) do
         | 
| 26 | 
            -
                           | 
| 33 | 
            +
                          Connection.new(
         | 
| 34 | 
            +
                            excon: ::Excon.new(
         | 
| 35 | 
            +
                              url,
         | 
| 36 | 
            +
                              persistent: true,
         | 
| 37 | 
            +
                              thread_safe_sockets: false
         | 
| 38 | 
            +
                            ),
         | 
| 39 | 
            +
                            idle_timeout: config.fetch(:idle_timeout, FaradayPersistentExcon.idle_timeout)
         | 
| 40 | 
            +
                          )
         | 
| 27 41 | 
             
                        end
         | 
| 28 42 | 
             
                      end
         | 
| 29 43 | 
             
                    end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: faraday_persistent_excon
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.3.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Ryan Schlesinger
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-08- | 
| 11 | 
            +
            date: 2015-08-26 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: faraday
         | 
| @@ -141,6 +141,7 @@ files: | |
| 141 141 | 
             
            - faraday_persistent_excon.gemspec
         | 
| 142 142 | 
             
            - lib/faraday_persistent_excon.rb
         | 
| 143 143 | 
             
            - lib/faraday_persistent_excon/adapter.rb
         | 
| 144 | 
            +
            - lib/faraday_persistent_excon/connection.rb
         | 
| 144 145 | 
             
            - lib/faraday_persistent_excon/connection_pools.rb
         | 
| 145 146 | 
             
            - lib/faraday_persistent_excon/perform_request.rb
         | 
| 146 147 | 
             
            - lib/faraday_persistent_excon/request_options.rb
         |