pydocket 0.6.4__py3-none-any.whl → 0.7.0__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.
Potentially problematic release.
This version of pydocket might be problematic. Click here for more details.
- docket/dependencies.py +19 -4
- {pydocket-0.6.4.dist-info → pydocket-0.7.0.dist-info}/METADATA +1 -1
- {pydocket-0.6.4.dist-info → pydocket-0.7.0.dist-info}/RECORD +6 -6
- {pydocket-0.6.4.dist-info → pydocket-0.7.0.dist-info}/WHEEL +0 -0
- {pydocket-0.6.4.dist-info → pydocket-0.7.0.dist-info}/entry_points.txt +0 -0
- {pydocket-0.6.4.dist-info → pydocket-0.7.0.dist-info}/licenses/LICENSE +0 -0
docket/dependencies.py
CHANGED
|
@@ -3,7 +3,7 @@ import logging
|
|
|
3
3
|
import time
|
|
4
4
|
from contextlib import AsyncExitStack, asynccontextmanager
|
|
5
5
|
from contextvars import ContextVar
|
|
6
|
-
from datetime import timedelta
|
|
6
|
+
from datetime import datetime, timedelta, timezone
|
|
7
7
|
from types import TracebackType
|
|
8
8
|
from typing import (
|
|
9
9
|
TYPE_CHECKING,
|
|
@@ -14,6 +14,7 @@ from typing import (
|
|
|
14
14
|
Callable,
|
|
15
15
|
Counter,
|
|
16
16
|
Generic,
|
|
17
|
+
NoReturn,
|
|
17
18
|
TypeVar,
|
|
18
19
|
cast,
|
|
19
20
|
)
|
|
@@ -188,6 +189,10 @@ def TaskLogger() -> logging.LoggerAdapter[logging.Logger]:
|
|
|
188
189
|
return cast(logging.LoggerAdapter[logging.Logger], _TaskLogger())
|
|
189
190
|
|
|
190
191
|
|
|
192
|
+
class ForcedRetry(Exception):
|
|
193
|
+
"""Raised when a task requests a retry via `in_` or `at`"""
|
|
194
|
+
|
|
195
|
+
|
|
191
196
|
class Retry(Dependency):
|
|
192
197
|
"""Configures linear retries for a task. You can specify the total number of
|
|
193
198
|
attempts (or `None` to retry indefinitely), and the delay between attempts.
|
|
@@ -222,6 +227,17 @@ class Retry(Dependency):
|
|
|
222
227
|
retry.attempt = execution.attempt
|
|
223
228
|
return retry
|
|
224
229
|
|
|
230
|
+
def at(self, when: datetime) -> NoReturn:
|
|
231
|
+
now = datetime.now(timezone.utc)
|
|
232
|
+
diff = when - now
|
|
233
|
+
diff = diff if diff.total_seconds() >= 0 else timedelta(0)
|
|
234
|
+
|
|
235
|
+
self.in_(diff)
|
|
236
|
+
|
|
237
|
+
def in_(self, when: timedelta) -> NoReturn:
|
|
238
|
+
self.delay: timedelta = when
|
|
239
|
+
raise ForcedRetry()
|
|
240
|
+
|
|
225
241
|
|
|
226
242
|
class ExponentialRetry(Retry):
|
|
227
243
|
"""Configures exponential retries for a task. You can specify the total number
|
|
@@ -251,7 +267,6 @@ class ExponentialRetry(Retry):
|
|
|
251
267
|
maximum_delay: The maximum delay between attempts.
|
|
252
268
|
"""
|
|
253
269
|
super().__init__(attempts=attempts, delay=minimum_delay)
|
|
254
|
-
self.minimum_delay = minimum_delay
|
|
255
270
|
self.maximum_delay = maximum_delay
|
|
256
271
|
|
|
257
272
|
async def __aenter__(self) -> "ExponentialRetry":
|
|
@@ -259,14 +274,14 @@ class ExponentialRetry(Retry):
|
|
|
259
274
|
|
|
260
275
|
retry = ExponentialRetry(
|
|
261
276
|
attempts=self.attempts,
|
|
262
|
-
minimum_delay=self.
|
|
277
|
+
minimum_delay=self.delay,
|
|
263
278
|
maximum_delay=self.maximum_delay,
|
|
264
279
|
)
|
|
265
280
|
retry.attempt = execution.attempt
|
|
266
281
|
|
|
267
282
|
if execution.attempt > 1:
|
|
268
283
|
backoff_factor = 2 ** (execution.attempt - 1)
|
|
269
|
-
calculated_delay = self.
|
|
284
|
+
calculated_delay = self.delay * backoff_factor
|
|
270
285
|
|
|
271
286
|
if calculated_delay > self.maximum_delay:
|
|
272
287
|
retry.delay = self.maximum_delay
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pydocket
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: A distributed background task system for Python functions
|
|
5
5
|
Project-URL: Homepage, https://github.com/chrisguidry/docket
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/chrisguidry/docket/issues
|
|
@@ -2,15 +2,15 @@ docket/__init__.py,sha256=sY1T_NVsXQNOmOhOnfYmZ95dcE_52Ov6DSIVIMZp-1w,869
|
|
|
2
2
|
docket/__main__.py,sha256=wcCrL4PjG51r5wVKqJhcoJPTLfHW0wNbD31DrUN0MWI,28
|
|
3
3
|
docket/annotations.py,sha256=SFBrOMbpAh7P67u8fRTH-u3MVvJQxe0qYi92WAShAsw,2173
|
|
4
4
|
docket/cli.py,sha256=WPm_URZ54h8gHjrsHKP8SXpRzdeepmyH_FhQHai-Qus,20899
|
|
5
|
-
docket/dependencies.py,sha256=
|
|
5
|
+
docket/dependencies.py,sha256=fX4vafGjQf7s4x0YROaw7fzQPlYW7TZtCqNhu7Kxj40,16831
|
|
6
6
|
docket/docket.py,sha256=5e101CGLZ2tWNcADo4cdewapmXab47ieMCeQr6d92YQ,24478
|
|
7
7
|
docket/execution.py,sha256=6KozjnS96byvyCMTQ2-IkcIrPsqaPIVu2HZU0U4Be9E,14813
|
|
8
8
|
docket/instrumentation.py,sha256=f-GG5VS6EdS2It30qxjVpzWUBOZQcTnat-3KzPwwDgQ,5367
|
|
9
9
|
docket/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
10
|
docket/tasks.py,sha256=RIlSM2omh-YDwVnCz6M5MtmK8T_m_s1w2OlRRxDUs6A,1437
|
|
11
11
|
docket/worker.py,sha256=tJfk2rlHODzHaWBzpBXT8h-Lo7RDQ6gb6HU8b3T9gFA,27878
|
|
12
|
-
pydocket-0.
|
|
13
|
-
pydocket-0.
|
|
14
|
-
pydocket-0.
|
|
15
|
-
pydocket-0.
|
|
16
|
-
pydocket-0.
|
|
12
|
+
pydocket-0.7.0.dist-info/METADATA,sha256=soXf7ybhgvSykxRDH56pMJX2DaXf3SJfDFUFLbebAvM,5335
|
|
13
|
+
pydocket-0.7.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
14
|
+
pydocket-0.7.0.dist-info/entry_points.txt,sha256=4WOk1nUlBsUT5O3RyMci2ImuC5XFswuopElYcLHtD5k,47
|
|
15
|
+
pydocket-0.7.0.dist-info/licenses/LICENSE,sha256=YuVWU_ZXO0K_k2FG8xWKe5RGxV24AhJKTvQmKfqXuyk,1087
|
|
16
|
+
pydocket-0.7.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|