fulfil_api 0.3.4 → 0.4.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 +4 -4
- data/lib/fulfil_api/relation/batchable.rb +17 -3
- data/lib/fulfil_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f706f1447ba368807d50288d63e7f12d944bc6632b0f59a00ff66cd31a50a147
|
|
4
|
+
data.tar.gz: 1f5ca01f9c3366b23d638eed39153a81ca37407f0f421bc2958480fe28e80dd2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 57d432e5078173cb1e5f5031b221d017fb6e6c3c71b5071ae48d2714972a7e09feaa121d339b5b12ede9a77eee2e54d5af1c4351add3fbf89721269a30c8884d
|
|
7
|
+
data.tar.gz: 548aaf65279ddeed350ca947bcacea6893ef47c108d781e805b6d76fc4e4c1122c95f0d0bd2b2fa0591e17f53c5fb8a312bd036ff690d49861d260cce5a3d601
|
|
@@ -5,6 +5,10 @@ module FulfilApi
|
|
|
5
5
|
# The {FulfilApi::Relation::Batchable} module includes a set of
|
|
6
6
|
# helper/query methods that queries resources in Fulfil in batches.
|
|
7
7
|
module Batchable
|
|
8
|
+
# The `RetryLimitExceeded` is raised when the maximum number of retry requests has
|
|
9
|
+
# been exceeded and we have no other option to cut off the retry mechanism.
|
|
10
|
+
class RetryLimitExceeded < Error; end
|
|
11
|
+
|
|
8
12
|
# The {#find_each} is a shorthand for iterating over individual API resources
|
|
9
13
|
# in a memory effective way.
|
|
10
14
|
#
|
|
@@ -41,10 +45,12 @@ module FulfilApi
|
|
|
41
45
|
# (TooManyRequests) HTTP error to ensure the lookup can be completed.
|
|
42
46
|
#
|
|
43
47
|
# @param of [Integer] The maximum number of resources in a batch.
|
|
48
|
+
# @param retries [Symbol, Integer] The maximum number of retries before raising.
|
|
44
49
|
# @yield [FulfilApi::Relation] Yields FulfilApi::Relation
|
|
45
50
|
# objects to work with a batch of records.
|
|
46
51
|
# @return [FulfilApi::Relation]
|
|
47
|
-
def in_batches(of: 500) # rubocop:disable Metrics/MethodLength
|
|
52
|
+
def in_batches(of: 500, retries: :unlimited) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
|
53
|
+
current_retry = 0
|
|
48
54
|
current_offset = request_offset.presence || 0
|
|
49
55
|
batch_size = of
|
|
50
56
|
|
|
@@ -58,9 +64,17 @@ module FulfilApi
|
|
|
58
64
|
|
|
59
65
|
current_offset += 1
|
|
60
66
|
rescue FulfilApi::Error => e
|
|
61
|
-
|
|
67
|
+
if e.details[:response_status] == 429
|
|
68
|
+
if retries != :unlimited && current_retry > retries
|
|
69
|
+
raise RetryLimitExceeded, "the maximum number of #{retries} retries has been reached."
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
current_retry += 1
|
|
73
|
+
sleep 0.25
|
|
74
|
+
retry
|
|
75
|
+
end
|
|
62
76
|
|
|
63
|
-
|
|
77
|
+
raise e
|
|
64
78
|
end
|
|
65
79
|
|
|
66
80
|
self
|
data/lib/fulfil_api/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fulfil_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stefan Vermaas
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-11-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|