hydrafetch 0.7.0 → 0.8.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
  SHA256:
3
- metadata.gz: bdf2b68d39f76d921042d0995c8686d58716b288884c919b6302943ee852f591
4
- data.tar.gz: 61cfab340278a3bbae9c5af93bd7d3a492e28ca3d2ff8ccb6a40dcfd6d9f9c5b
3
+ metadata.gz: 965080a26c2ea8d7dff1ba22650813befcb8550e1ff34f24a35f797498414e3e
4
+ data.tar.gz: 953227cd85d06a7a7e57c7f36a7ed890648b7fe48478f60bff4ce07adac1fb2d
5
5
  SHA512:
6
- metadata.gz: 4da1f0021b7f34e10f403ef305e560d0f6f0b2782fb280d2b96ef92fe70d8176402cc91fe5308ed799d03cbfcec8162942aec5dc05edbe553c8e6ecd470df411
7
- data.tar.gz: 2d1a22c4113af9597730eeaa99470cd7e505b35d8985869e1ee9449778c56bf38b14737e7be8d011a80715d14e45704a9df6f8186fe7d0611812441ed20d78c9
6
+ metadata.gz: 7847bb450f9dda5693519f82e3899326508d398c7ace1055a10671699013f7589b2944f2bad0abc374207a0fcfdbb87e2e341c5972dd7e947ef8ac3c657aea22
7
+ data.tar.gz: c9fddce74fb9b98987147d85cbac5a00650cbe2578348531f31025c016545cf75984c8cbc533c45a927096ef560f8371d6702f025880099fa1ccaca759e28c2d
data/README.md CHANGED
@@ -205,7 +205,7 @@ end
205
205
  | 429 | rate limited | yes, twice |
206
206
  | 5xx | upstream failure | yes, twice |
207
207
 
208
- Retries wait as long as the response asks through `Retry-After` or `retryAfterSeconds`, and otherwise back off with jitter. When the response asks for more than 30 seconds the client does not wait; it raises at once and `e.retry_after` gives the seconds to wait before asking again. A dropped connection is retried too, including while the client follows a job, and a job that fails is never started a second time.
208
+ Retries wait as long as the response asks through `Retry-After` or `retryAfterSeconds`, and otherwise back off with jitter. When the response asks for more than 30 seconds the client does not wait; it raises at once and `e.retry_after` gives the seconds to wait before asking again. A dropped connection is retried too, including while the client follows a job, and a job that fails is never started a second time. Every POST carries an Idempotency-Key that its own retries reuse, so a retry after a dropped connection returns the first answer instead of running and charging again.
209
209
 
210
210
  A 503 from `scrape` means the origin is unreachable, usually a dead domain or a broken certificate.
211
211
 
@@ -1,4 +1,5 @@
1
1
  require "json"
2
+ require "securerandom"
2
3
  require "net/http"
3
4
  require "time"
4
5
  require "uri"
@@ -185,10 +186,12 @@ module Hydrafetch
185
186
  uri.query = URI.encode_www_form(query) unless query.nil? || query.empty?
186
187
 
187
188
  attempt = 0
189
+ idempotency_key = verb == Net::HTTP::Post ? SecureRandom.uuid : nil
188
190
  begin
189
191
  req = verb.new(uri)
190
192
  req["X-API-Key"] = @api_key
191
193
  req["Accept"] = "application/json"
194
+ req["Idempotency-Key"] = idempotency_key if idempotency_key
192
195
  if body
193
196
  req["Content-Type"] = "application/json"
194
197
  req.body = JSON.generate(body)
@@ -31,7 +31,7 @@ module Hydrafetch
31
31
  end
32
32
 
33
33
  def retryable?
34
- status == 429 || status >= 500
34
+ status == 429 || status >= 500 || code == "IDEMPOTENCY_IN_PROGRESS"
35
35
  end
36
36
 
37
37
  def timeout?
@@ -1,3 +1,3 @@
1
1
  module Hydrafetch
2
- VERSION = "0.7.0".freeze
2
+ VERSION = "0.8.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydrafetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hydrafetch