ghost_reader 1.2.0 → 1.2.1
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.
- data/lib/ghost_reader/backend.rb +3 -26
- data/lib/ghost_reader/client.rb +11 -6
- data/lib/ghost_reader/version.rb +1 -1
- metadata +4 -4
    
        data/lib/ghost_reader/backend.rb
    CHANGED
    
    | @@ -65,7 +65,7 @@ module GhostReader | |
| 65 65 | 
             
                    diff = Time.now - @report_ts
         | 
| 66 66 | 
             
                    if diff > config.report_interval
         | 
| 67 67 | 
             
                      threadify do
         | 
| 68 | 
            -
                        log "Kick off report. #{missings.inspect}" | 
| 68 | 
            +
                        log "Kick off report. #{missings.inspect}"
         | 
| 69 69 | 
             
                        @report_ts = Time.now
         | 
| 70 70 | 
             
                        report
         | 
| 71 71 | 
             
                        @report_ts = Time.now
         | 
| @@ -102,18 +102,6 @@ module GhostReader | |
| 102 102 | 
             
                    memoized_lookup.send(options[:method], symbolized_flattend)
         | 
| 103 103 | 
             
                  end
         | 
| 104 104 |  | 
| 105 | 
            -
                  # # performs initial and incremental requests
         | 
| 106 | 
            -
                  # def spawn_retriever
         | 
| 107 | 
            -
                  #   log "Spawning retriever."
         | 
| 108 | 
            -
                  #   @retriever = Thread.new do
         | 
| 109 | 
            -
                  #     initialize_retrieval
         | 
| 110 | 
            -
                  #     until false
         | 
| 111 | 
            -
                  #       sleep config.retrieval_interval
         | 
| 112 | 
            -
                  #       retrieve
         | 
| 113 | 
            -
                  #     end
         | 
| 114 | 
            -
                  #   end
         | 
| 115 | 
            -
                  # end
         | 
| 116 | 
            -
             | 
| 117 105 | 
             
                  def initialize_retrieval
         | 
| 118 106 | 
             
                    log "Performing initial request."
         | 
| 119 107 | 
             
                    response = config.client.initial_request
         | 
| @@ -132,31 +120,20 @@ module GhostReader | |
| 132 120 | 
             
                      log "Data: #{response[:data].inspect}"
         | 
| 133 121 | 
             
                      memoize_merge! response[:data], :method => :deep_merge!
         | 
| 134 122 | 
             
                    else
         | 
| 135 | 
            -
                      log "Incremental request, but no data."
         | 
| 123 | 
            +
                      log "Incremental request, but no data.", :info
         | 
| 136 124 | 
             
                    end
         | 
| 137 125 | 
             
                  rescue => ex
         | 
| 138 126 | 
             
                    log "Exception in retrieval: #{ex}", :error
         | 
| 139 127 | 
             
                    log ex.backtrace.join("\n"), :error
         | 
| 140 128 | 
             
                  end
         | 
| 141 129 |  | 
| 142 | 
            -
                  # # performs reporting requests
         | 
| 143 | 
            -
                  # def spawn_reporter
         | 
| 144 | 
            -
                  #   log "Spawning reporter."
         | 
| 145 | 
            -
                  #   @reporter = Thread.new do
         | 
| 146 | 
            -
                  #     until false
         | 
| 147 | 
            -
                  #       sleep config.report_interval
         | 
| 148 | 
            -
                  #       report
         | 
| 149 | 
            -
                  #     end
         | 
| 150 | 
            -
                  #   end
         | 
| 151 | 
            -
                  # end
         | 
| 152 | 
            -
             | 
| 153 130 | 
             
                  def report
         | 
| 154 131 | 
             
                    unless self.missings.nil?
         | 
| 155 132 | 
             
                      unless self.missings.empty?
         | 
| 156 133 | 
             
                        log "Reporting request with #{self.missings.keys.size} missings.", :info
         | 
| 157 134 | 
             
                        config.client.reporting_request(missings)
         | 
| 158 135 | 
             
                        self.missings.clear
         | 
| 159 | 
            -
                        log "Missings emptied." | 
| 136 | 
            +
                        log "Missings emptied."
         | 
| 160 137 | 
             
                      else
         | 
| 161 138 | 
             
                        log "Reporting request omitted, nothing to report."
         | 
| 162 139 | 
             
                      end
         | 
    
        data/lib/ghost_reader/client.rb
    CHANGED
    
    | @@ -24,7 +24,7 @@ module GhostReader | |
| 24 24 | 
             
                # returns true if redirected, false otherwise
         | 
| 25 25 | 
             
                def reporting_request(data)
         | 
| 26 26 | 
             
                  response = connect_with_retry(:post, :body => "data=#{data.to_json}")
         | 
| 27 | 
            -
                   | 
| 27 | 
            +
                  log("Reporting request not redirected", :error) unless response.status == 302
         | 
| 28 28 | 
             
                  { :status => response.status }
         | 
| 29 29 | 
             
                end
         | 
| 30 30 |  | 
| @@ -41,7 +41,7 @@ module GhostReader | |
| 41 41 |  | 
| 42 42 | 
             
                # this is just a wrapper to have a log message when the field is set
         | 
| 43 43 | 
             
                def last_modified=(value)
         | 
| 44 | 
            -
                   | 
| 44 | 
            +
                  log "Last-Modified: #{value}"
         | 
| 45 45 | 
             
                  @last_modified = value
         | 
| 46 46 | 
             
                end
         | 
| 47 47 |  | 
| @@ -61,21 +61,21 @@ module GhostReader | |
| 61 61 | 
             
                  raise 'no api_key provided' if config.api_key.nil?
         | 
| 62 62 | 
             
                  @address ||= config.uri.
         | 
| 63 63 | 
             
                    sub(':protocol', config.protocol).
         | 
| 64 | 
            -
                    sub(':host', | 
| 65 | 
            -
                    sub(':api_key', | 
| 64 | 
            +
                    sub(':host',     config.host).
         | 
| 65 | 
            +
                    sub(':api_key',  config.api_key)
         | 
| 66 66 | 
             
                end
         | 
| 67 67 |  | 
| 68 68 | 
             
                # Wrapper method for retrying the connection
         | 
| 69 69 | 
             
                #   :method - http method (post and get supported at the moment)
         | 
| 70 70 | 
             
                #   :params - parameters sent to the service (excon)
         | 
| 71 71 | 
             
                def connect_with_retry(method = :get, params = {})
         | 
| 72 | 
            -
                   | 
| 72 | 
            +
                  log "Request: #{method} #{params.inspect}"
         | 
| 73 73 | 
             
                  retries = self.config.connection_retries
         | 
| 74 74 | 
             
                  while (retries > 0) do
         | 
| 75 75 | 
             
                    response = service.request(params.merge(:method => method))
         | 
| 76 76 |  | 
| 77 77 | 
             
                    if response.status == 408
         | 
| 78 | 
            -
                       | 
| 78 | 
            +
                      log "Connection time-out. Retrying... #{retries}", :error
         | 
| 79 79 | 
             
                      retries -= 1
         | 
| 80 80 | 
             
                    else
         | 
| 81 81 | 
             
                      retries = 0 # There is no timeout, no need to retry
         | 
| @@ -93,5 +93,10 @@ module GhostReader | |
| 93 93 | 
             
                    :connection_retries => 3
         | 
| 94 94 | 
             
                  }
         | 
| 95 95 | 
             
                end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                def log(msg, level=:debug)
         | 
| 98 | 
            +
                  config.logger.send(level, "[#{$$}] #{msg}")
         | 
| 99 | 
            +
                end
         | 
| 100 | 
            +
             | 
| 96 101 | 
             
              end
         | 
| 97 102 | 
             
            end
         | 
    
        data/lib/ghost_reader/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: ghost_reader
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 29
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 1
         | 
| 8 8 | 
             
              - 2
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 1.2. | 
| 9 | 
            +
              - 1
         | 
| 10 | 
            +
              version: 1.2.1
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Phil Hofmann
         | 
| @@ -15,7 +15,7 @@ autorequire: | |
| 15 15 | 
             
            bindir: bin
         | 
| 16 16 | 
             
            cert_chain: []
         | 
| 17 17 |  | 
| 18 | 
            -
            date: 2012-01- | 
| 18 | 
            +
            date: 2012-01-19 00:00:00 +01:00
         | 
| 19 19 | 
             
            default_executable: 
         | 
| 20 20 | 
             
            dependencies: 
         | 
| 21 21 | 
             
            - !ruby/object:Gem::Dependency 
         |