iker-python-common 1.0.51__py3-none-any.whl → 1.0.52__py3-none-any.whl
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.
- iker/common/utils/retry.py +17 -17
- {iker_python_common-1.0.51.dist-info → iker_python_common-1.0.52.dist-info}/METADATA +1 -1
- {iker_python_common-1.0.51.dist-info → iker_python_common-1.0.52.dist-info}/RECORD +5 -5
- {iker_python_common-1.0.51.dist-info → iker_python_common-1.0.52.dist-info}/WHEEL +0 -0
- {iker_python_common-1.0.51.dist-info → iker_python_common-1.0.52.dist-info}/top_level.txt +0 -0
iker/common/utils/retry.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import abc
|
|
2
|
-
import datetime
|
|
3
2
|
import random
|
|
4
3
|
import time
|
|
5
4
|
|
|
6
5
|
from iker.common.utils import logger
|
|
6
|
+
from iker.common.utils.dtutils import dt_utc_now
|
|
7
7
|
|
|
8
8
|
__all__ = [
|
|
9
9
|
"Attempt",
|
|
@@ -21,8 +21,8 @@ class Attempt(object):
|
|
|
21
21
|
number: int,
|
|
22
22
|
prev_wait: int,
|
|
23
23
|
next_wait: int,
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
start_ts: float,
|
|
25
|
+
check_ts: float,
|
|
26
26
|
last_exception: Exception,
|
|
27
27
|
):
|
|
28
28
|
"""
|
|
@@ -31,15 +31,15 @@ class Attempt(object):
|
|
|
31
31
|
:param number: The attempt number (1-based).
|
|
32
32
|
:param prev_wait: The wait time before the previous attempt (in seconds).
|
|
33
33
|
:param next_wait: The wait time before the next attempt (in seconds).
|
|
34
|
-
:param
|
|
35
|
-
:param
|
|
34
|
+
:param start_ts: The start timestamp of the first attempt.
|
|
35
|
+
:param check_ts: The timestamp at which the current attempt is checked.
|
|
36
36
|
:param last_exception: The exception raised during the last attempt, if any.
|
|
37
37
|
"""
|
|
38
38
|
self.number = number
|
|
39
39
|
self.prev_wait = prev_wait
|
|
40
40
|
self.next_wait = next_wait
|
|
41
|
-
self.
|
|
42
|
-
self.
|
|
41
|
+
self.start_ts = start_ts
|
|
42
|
+
self.check_ts = check_ts
|
|
43
43
|
self.last_exception = last_exception
|
|
44
44
|
|
|
45
45
|
|
|
@@ -127,17 +127,17 @@ class RetryWrapper(object):
|
|
|
127
127
|
else:
|
|
128
128
|
return 0
|
|
129
129
|
|
|
130
|
-
def __check_timeout(self,
|
|
130
|
+
def __check_timeout(self, start_ts: float) -> tuple[bool, float]:
|
|
131
131
|
"""
|
|
132
132
|
Checks if the retry operation has exceeded the configured timeout.
|
|
133
133
|
|
|
134
|
-
:param
|
|
135
|
-
:return: Tuple (``True`` if within timeout, current
|
|
134
|
+
:param start_ts: The start timestamp of the first attempt.
|
|
135
|
+
:return: Tuple (``True`` if within timeout, current timestamp).
|
|
136
136
|
"""
|
|
137
|
-
|
|
137
|
+
current_ts = dt_utc_now().timestamp()
|
|
138
138
|
if self.timeout is None:
|
|
139
|
-
return True,
|
|
140
|
-
return
|
|
139
|
+
return True, current_ts
|
|
140
|
+
return current_ts < start_ts + self.timeout, current_ts
|
|
141
141
|
|
|
142
142
|
def __run(self, *args, **kwargs):
|
|
143
143
|
"""
|
|
@@ -150,13 +150,13 @@ class RetryWrapper(object):
|
|
|
150
150
|
:raises RuntimeError: If all attempts fail or timeout is reached.
|
|
151
151
|
"""
|
|
152
152
|
attempt_number = 0
|
|
153
|
-
|
|
153
|
+
start_ts = dt_utc_now().timestamp()
|
|
154
154
|
last_exception = None
|
|
155
155
|
|
|
156
156
|
while self.retrials is None or attempt_number <= self.retrials:
|
|
157
157
|
attempt_number += 1
|
|
158
158
|
|
|
159
|
-
check_result,
|
|
159
|
+
check_result, check_ts = self.__check_timeout(start_ts)
|
|
160
160
|
if not check_result:
|
|
161
161
|
break
|
|
162
162
|
|
|
@@ -164,8 +164,8 @@ class RetryWrapper(object):
|
|
|
164
164
|
attempt_number,
|
|
165
165
|
self.__next_wait(attempt_number - 1),
|
|
166
166
|
self.__next_wait(attempt_number),
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
start_ts,
|
|
168
|
+
check_ts,
|
|
169
169
|
last_exception,
|
|
170
170
|
)
|
|
171
171
|
try:
|
|
@@ -11,7 +11,7 @@ iker/common/utils/jsonutils.py,sha256=xYKimWtsqQKiQDQr3EMIhpGrmWSNPzgZR1Sdz60CxS
|
|
|
11
11
|
iker/common/utils/logger.py,sha256=FJaai6Sbchy4wKHcUMUCrrkBcXvIxq4qByERZ_TJBps,3881
|
|
12
12
|
iker/common/utils/numutils.py,sha256=vg739jMqx3W1H_IxzzSJKhtEGZEnQrNgsp_tDKhEVck,4432
|
|
13
13
|
iker/common/utils/randutils.py,sha256=PuQVSKNOtXTgQh8QCifMMgsGzmevkrInSSKpnqD361Q,12816
|
|
14
|
-
iker/common/utils/retry.py,sha256=
|
|
14
|
+
iker/common/utils/retry.py,sha256=H9lR6pp_jzgOwKTM-dOWIddjTlQbK-ijcwuDmVvurZM,8938
|
|
15
15
|
iker/common/utils/s3utils.py,sha256=rb-JVCJuIbmVn4ml7MQ7qKD8Z25t8xnU_u4oY1-APe4,9368
|
|
16
16
|
iker/common/utils/sequtils.py,sha256=MfYL82TygBRlGK4sw0RJcoB5P3hO6l7saVH5oZ3YDP8,25003
|
|
17
17
|
iker/common/utils/shutils.py,sha256=44_Qkzkhrs9LsfDflsaY_4Va0IpVLU3o8K_NvqCB04w,7859
|
|
@@ -19,7 +19,7 @@ iker/common/utils/span.py,sha256=yiXqk86cLKxkMdkO3pAHEfU5bUvHsGo3p--pAWo_yfM,599
|
|
|
19
19
|
iker/common/utils/strutils.py,sha256=Tu_qFeH3K-SfwvMxdrZAc9iLPV8ZmtX4ntyyFGNslf8,5094
|
|
20
20
|
iker/common/utils/testutils.py,sha256=2VieV5yeCDntSKQSpIeyqRT8BZmZYE_ArMeQz3g7fXY,5568
|
|
21
21
|
iker/common/utils/typeutils.py,sha256=RVkYkFRgDrx77OHFH7PavMV0AIB0S8ly40rs4g7JWE4,8220
|
|
22
|
-
iker_python_common-1.0.
|
|
23
|
-
iker_python_common-1.0.
|
|
24
|
-
iker_python_common-1.0.
|
|
25
|
-
iker_python_common-1.0.
|
|
22
|
+
iker_python_common-1.0.52.dist-info/METADATA,sha256=xX-lcqFtKgi1VKIvTeQj7D5po6gZrK38dWGEHmAw08U,1001
|
|
23
|
+
iker_python_common-1.0.52.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
24
|
+
iker_python_common-1.0.52.dist-info/top_level.txt,sha256=4_B8Prfc_lxFafFYTQThIU1ZqOYQ4pHHHnJ_fQ_oHs8,5
|
|
25
|
+
iker_python_common-1.0.52.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|