Class: Net::HTTP::FollowTail::Tailer
- Inherits:
-
Reindeer
- Object
- Reindeer
- Net::HTTP::FollowTail::Tailer
- Defined in:
- lib/net/http/follow_tail.rb
Instance Method Summary collapse
- #build(opts) ⇒ Object
-
#error_wait ⇒ Object
This and regular_wait need new names!.
- #get_request(size_now) ⇒ Object
- #head_request ⇒ Object
- #regular_wait ⇒ Object
- #still_following? ⇒ Boolean
- #tail ⇒ Object
- #update_offset(offset_increment) ⇒ Object
Instance Method Details
#build(opts) ⇒ Object
38 39 40 |
# File 'lib/net/http/follow_tail.rb', line 38 def build(opts) @uri = opts[:uri].kind_of?(URI::HTTP) ? opts[:uri] : URI.parse(opts[:uri]) end |
#error_wait ⇒ Object
This and regular_wait need new names!
47 48 49 50 51 52 53 |
# File 'lib/net/http/follow_tail.rb', line 47 def error_wait if exponential_backoff.length > 1 exponential_backoff.shift else exponential_backoff.first end end |
#get_request(size_now) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/net/http/follow_tail.rb', line 69 def get_request(size_now) http = Net::HTTP.new(uri.host, uri.port) req = Net::HTTP::Get.new(uri.to_s) req.initialize_http_header('Range' => "bytes=#{offset}-#{size_now}") http.request(req) end |
#head_request ⇒ Object
64 65 66 67 |
# File 'lib/net/http/follow_tail.rb', line 64 def head_request http = Net::HTTP.new(uri.host, uri.port) http.request( Net::HTTP::Head.new(uri.to_s) ) end |
#regular_wait ⇒ Object
54 55 56 57 58 |
# File 'lib/net/http/follow_tail.rb', line 54 def regular_wait @exponential_backoff = get_backoff_list @retries_so_far = 0 wait_in_seconds end |
#still_following? ⇒ Boolean
42 43 44 |
# File 'lib/net/http/follow_tail.rb', line 42 def still_following? @still_following end |
#tail ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/net/http/follow_tail.rb', line 76 def tail @retries_so_far += 1 begin head_response = head_request rescue Timeout::Error, SocketError, EOFError, Errno::ETIMEDOUT, Errno::ENETUNREACH, Errno::EHOSTUNREACH => err return Result.new(state: :error, method: :head, error: err) end # TODO invoke head_response.value to check for non 200s. size_now = head_response.content_length if size_now == offset return Result.new(state: :no_change, method: :head, response: head_response) end begin get_response = get_request(size_now) rescue Timeout::Error, SocketError, EOFError, Errno::ETIMEDOUT, Errno::ENETUNREACH, Errno::EHOSTUNREACH => err return Result.new(state: :error, method: :get, error: err) end update_offset get_response.content_length # yield get_response, offset_for(uri) return Result.new(state: :success, method: :get, response: get_response) end |
#update_offset(offset_increment) ⇒ Object
60 61 62 |
# File 'lib/net/http/follow_tail.rb', line 60 def update_offset(offset_increment) @offset += offset_increment.to_i end |