@@ -86,6 +86,7 @@ class ShopifyRateLimiter:
86
86
"""
87
87
88
88
on_unknown_load : float = 1.0
89
+ on_very_low_load : float = 0.0
89
90
on_low_load : float = 0.2
90
91
on_mid_load : float = 1.5
91
92
on_high_load : float = 5.0
@@ -122,20 +123,26 @@ def _convert_load_to_time(load: Optional[float], threshold: float) -> float:
122
123
:: wait_time - time to wait between each request in seconds
123
124
124
125
"""
125
- mid_load = threshold / 2 # average load based on threshold
126
+
127
+ half_of_threshold = threshold / 2 # average load based on threshold
128
+ quarter_of_threshold = threshold / 4 # low load based on threshold
129
+
126
130
if not load :
127
131
# when there is no rate_limits from header, use the `sleep_on_unknown_load`
128
132
wait_time = ShopifyRateLimiter .on_unknown_load
129
133
ShopifyRateLimiter .log_message_counter ("API Load: `REGULAR`" )
130
- elif load >= threshold :
134
+ elif threshold <= load :
131
135
wait_time = ShopifyRateLimiter .on_high_load
132
136
ShopifyRateLimiter .log_message_counter ("API Load: `HIGH`" )
133
- elif load >= mid_load :
137
+ elif half_of_threshold <= load < threshold :
134
138
wait_time = ShopifyRateLimiter .on_mid_load
135
139
ShopifyRateLimiter .log_message_counter ("API Load: `MID`" )
136
- elif load < mid_load :
140
+ elif quarter_of_threshold <= load < half_of_threshold :
137
141
wait_time = ShopifyRateLimiter .on_low_load
138
142
ShopifyRateLimiter .log_message_counter ("API Load: `LOW`" )
143
+ elif load < quarter_of_threshold :
144
+ wait_time = ShopifyRateLimiter .on_very_low_load
145
+
139
146
return wait_time
140
147
141
148
@staticmethod
@@ -219,22 +226,6 @@ def get_graphql_api_wait_time(*args, threshold: float = 0.9) -> float:
219
226
wait_time = ShopifyRateLimiter ._convert_load_to_time (load , threshold )
220
227
return wait_time
221
228
222
- def _debug_info (* args ) -> Any :
223
- # find the requests.Response inside args list
224
- response = ShopifyRateLimiter .get_response_from_args (* args )
225
-
226
- if response :
227
- try :
228
- content = response .json ()
229
- content_keys = list (content .keys ())
230
- stream_name = content_keys [0 ] if len (content_keys ) > 0 else None
231
- content_lengh = len (content .get (stream_name , [])) if stream_name else None
232
- debug_info = {"stream" : stream_name , "url" : response .request .url , "n_records" : content_lengh }
233
- return debug_info
234
- except (requests .JSONDecodeError , Exception ):
235
- # bypassing the errors, we don't care about it here
236
- pass
237
-
238
229
@staticmethod
239
230
def wait_time (wait_time : float ) -> None :
240
231
return sleep (wait_time )
0 commit comments