omnata-plugin-runtime 0.4.5a100__py3-none-any.whl → 0.4.6a101__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- omnata_plugin_runtime/rate_limiting.py +29 -3
- {omnata_plugin_runtime-0.4.5a100.dist-info → omnata_plugin_runtime-0.4.6a101.dist-info}/METADATA +1 -1
- {omnata_plugin_runtime-0.4.5a100.dist-info → omnata_plugin_runtime-0.4.6a101.dist-info}/RECORD +5 -5
- {omnata_plugin_runtime-0.4.5a100.dist-info → omnata_plugin_runtime-0.4.6a101.dist-info}/LICENSE +0 -0
- {omnata_plugin_runtime-0.4.5a100.dist-info → omnata_plugin_runtime-0.4.6a101.dist-info}/WHEEL +0 -0
@@ -8,7 +8,7 @@ import re
|
|
8
8
|
import threading
|
9
9
|
from email.utils import parsedate_to_datetime
|
10
10
|
from logging import getLogger
|
11
|
-
from typing import List, Literal, Optional, Dict, Tuple
|
11
|
+
from typing import Any, List, Literal, Optional, Dict, Tuple
|
12
12
|
import requests
|
13
13
|
from pydantic import Field, root_validator
|
14
14
|
from pydantic.json import pydantic_encoder
|
@@ -349,6 +349,32 @@ class RetryLaterException(Exception):
|
|
349
349
|
self.message = message
|
350
350
|
super().__init__(self.message)
|
351
351
|
|
352
|
+
class RetryWithLogging(Retry):
|
353
|
+
"""
|
354
|
+
Adding extra logs before making a retry request
|
355
|
+
"""
|
356
|
+
def __call__(self, *args: Any, thread_cancellation_token:threading.Event, **kwargs: Any) -> Any:
|
357
|
+
self.thread_cancellation_token = thread_cancellation_token
|
358
|
+
return super().__call__(*args, **kwargs)
|
359
|
+
|
360
|
+
def sleep_for_retry(self, response=None):
|
361
|
+
retry_after = self.get_retry_after(response)
|
362
|
+
if retry_after:
|
363
|
+
logger.info(f"Retrying after {retry_after} seconds due to Retry-After header")
|
364
|
+
if self.thread_cancellation_token.wait(retry_after):
|
365
|
+
raise InterruptedWhileWaitingException(message="The sync was interrupted while waiting for rate limiting to expire")
|
366
|
+
return True
|
367
|
+
return False
|
368
|
+
|
369
|
+
def _sleep_backoff(self):
|
370
|
+
backoff = self.get_backoff_time()
|
371
|
+
if backoff <= 0:
|
372
|
+
return
|
373
|
+
logger.info(f"Retrying after {backoff} seconds due to backoff time")
|
374
|
+
if self.thread_cancellation_token.wait(backoff):
|
375
|
+
raise InterruptedWhileWaitingException(message="The sync was interrupted while waiting for rate limiting to expire")
|
376
|
+
|
377
|
+
|
352
378
|
class RateLimitedSession(requests.Session):
|
353
379
|
"""
|
354
380
|
Creates a requests session that will automatically handle rate limiting.
|
@@ -366,7 +392,7 @@ class RateLimitedSession(requests.Session):
|
|
366
392
|
self.thread_cancellation_token = thread_cancellation_token
|
367
393
|
self.statuses_to_include = statuses_to_include
|
368
394
|
|
369
|
-
retry_strategy =
|
395
|
+
retry_strategy = RetryWithLogging(
|
370
396
|
total=max_retries,
|
371
397
|
backoff_factor=backoff_factor,
|
372
398
|
status_forcelist=statuses_to_include,
|
@@ -398,7 +424,7 @@ class RateLimitedSession(requests.Session):
|
|
398
424
|
def request(self, method, url, **kwargs):
|
399
425
|
while True:
|
400
426
|
response = super().request(method, url, **kwargs)
|
401
|
-
|
427
|
+
# TODO: this is probably all redundant as the Retry object should handle this at a lower level (urllib3)
|
402
428
|
if response.status_code in self.statuses_to_include:
|
403
429
|
if 'Retry-After' in response.headers:
|
404
430
|
retry_after = response.headers['Retry-After']
|
{omnata_plugin_runtime-0.4.5a100.dist-info → omnata_plugin_runtime-0.4.6a101.dist-info}/RECORD
RENAMED
@@ -5,8 +5,8 @@ omnata_plugin_runtime/forms.py,sha256=pw_aKVsXSz47EP8PFBI3VDwdSN5IjvZxp8JTjO1V13
|
|
5
5
|
omnata_plugin_runtime/logging.py,sha256=bn7eKoNWvtuyTk7RTwBS9UARMtqkiICtgMtzq3KA2V0,3272
|
6
6
|
omnata_plugin_runtime/omnata_plugin.py,sha256=UJZNTcG6s5APZ7EIOYc5N4bFiyFEq3ekbSP6EK7tCBY,108065
|
7
7
|
omnata_plugin_runtime/plugin_entrypoints.py,sha256=JAGEdVcy9QEXv7TO5zt7co64LTP8nqGusOc0sJG9GtU,29149
|
8
|
-
omnata_plugin_runtime/rate_limiting.py,sha256=
|
9
|
-
omnata_plugin_runtime-0.4.
|
10
|
-
omnata_plugin_runtime-0.4.
|
11
|
-
omnata_plugin_runtime-0.4.
|
12
|
-
omnata_plugin_runtime-0.4.
|
8
|
+
omnata_plugin_runtime/rate_limiting.py,sha256=9Cv0sGOFnQaF-SQJaqJIWGAzkTcBGaJ1USZU5khhQIQ,22798
|
9
|
+
omnata_plugin_runtime-0.4.6a101.dist-info/LICENSE,sha256=IMF9i4xIpgCADf0U-V1cuf9HBmqWQd3qtI3FSuyW4zE,26526
|
10
|
+
omnata_plugin_runtime-0.4.6a101.dist-info/METADATA,sha256=zUn9jISlyAuv1aU8oCAKgG1bTUrWgyYIJ-SEg9fOA_M,1642
|
11
|
+
omnata_plugin_runtime-0.4.6a101.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
12
|
+
omnata_plugin_runtime-0.4.6a101.dist-info/RECORD,,
|
{omnata_plugin_runtime-0.4.5a100.dist-info → omnata_plugin_runtime-0.4.6a101.dist-info}/LICENSE
RENAMED
File without changes
|
{omnata_plugin_runtime-0.4.5a100.dist-info → omnata_plugin_runtime-0.4.6a101.dist-info}/WHEEL
RENAMED
File without changes
|