ltq 0.1.1__py3-none-any.whl → 0.1.2__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.
ltq/task.py
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from
|
|
3
|
+
from functools import update_wrapper
|
|
4
|
+
from typing import Awaitable, Callable, Generic, ParamSpec, TypeVar
|
|
4
5
|
|
|
5
6
|
from .message import Message
|
|
6
7
|
from .q import Queue
|
|
7
8
|
|
|
8
9
|
P = ParamSpec("P")
|
|
10
|
+
R = TypeVar("R")
|
|
9
11
|
|
|
10
12
|
|
|
11
|
-
class Task(Generic[P]):
|
|
13
|
+
class Task(Generic[P, R]):
|
|
12
14
|
def __init__(
|
|
13
15
|
self,
|
|
14
16
|
name: str,
|
|
15
|
-
fn: Callable[P, Awaitable[
|
|
17
|
+
fn: Callable[P, Awaitable[R]],
|
|
16
18
|
queue: Queue,
|
|
17
19
|
ttl: int | None = None,
|
|
18
20
|
) -> None:
|
|
@@ -36,3 +38,6 @@ class Task(Generic[P]):
|
|
|
36
38
|
async def send_bulk(self, messages: list[Message]) -> list[str]:
|
|
37
39
|
await self.queue.put(messages, ttl=self.ttl)
|
|
38
40
|
return [message.id for message in messages]
|
|
41
|
+
|
|
42
|
+
async def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:
|
|
43
|
+
return await self.fn(*args, **kwargs)
|
ltq/worker.py
CHANGED
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import asyncio
|
|
4
4
|
from functools import partial
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import TYPE_CHECKING, Any, Awaitable, Callable, ParamSpec
|
|
6
|
+
from typing import TYPE_CHECKING, Any, Awaitable, Callable, ParamSpec, TypeVar
|
|
7
7
|
|
|
8
8
|
import redis.asyncio as redis
|
|
9
9
|
|
|
@@ -21,6 +21,7 @@ logger = get_logger()
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
P = ParamSpec("P")
|
|
24
|
+
R = TypeVar("R")
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
class Worker:
|
|
@@ -41,8 +42,8 @@ class Worker:
|
|
|
41
42
|
self,
|
|
42
43
|
queue_name: str | None = None,
|
|
43
44
|
ttl: int | None = None,
|
|
44
|
-
) -> Callable[[Callable[P, Awaitable[
|
|
45
|
-
def decorator(fn: Callable[P, Awaitable[
|
|
45
|
+
) -> Callable[[Callable[P, Awaitable[R]]], Task[P, R]]:
|
|
46
|
+
def decorator(fn: Callable[P, Awaitable[R]]) -> Task[P, R]:
|
|
46
47
|
filename = Path(fn.__code__.co_filename).stem
|
|
47
48
|
task_name = f"{filename}:{fn.__qualname__}"
|
|
48
49
|
queue = Queue(self.client, queue_name or task_name)
|
|
@@ -50,7 +51,7 @@ class Worker:
|
|
|
50
51
|
name=task_name,
|
|
51
52
|
fn=fn,
|
|
52
53
|
queue=queue,
|
|
53
|
-
ttl=ttl,
|
|
54
|
+
ttl=ttl,
|
|
54
55
|
)
|
|
55
56
|
self.tasks.append(task)
|
|
56
57
|
return task
|
|
@@ -89,5 +90,8 @@ class Worker:
|
|
|
89
90
|
await task.queue.ack(messages)
|
|
90
91
|
|
|
91
92
|
async def run(self) -> None:
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
try:
|
|
94
|
+
workers = (self.worker(task) for task in self.tasks)
|
|
95
|
+
await asyncio.gather(*workers)
|
|
96
|
+
finally:
|
|
97
|
+
await self.client.aclose()
|
|
@@ -5,9 +5,9 @@ ltq/logger.py,sha256=HPClhDt3ecwZqE0Vq2oYF8Nr9jj-xrsSX9tM6enVgkA,1791
|
|
|
5
5
|
ltq/message.py,sha256=C6gJR6KuRrnIb-l9Jna7e-XIu_aFHBhnZICUqE1_2MU,715
|
|
6
6
|
ltq/middleware.py,sha256=NMRI7UiJiUTqAHOB18Gz686mQGszSu-6hJiyTDPCKdE,3631
|
|
7
7
|
ltq/q.py,sha256=LddedNdb9uYD9qAjkzN0inBhvQ-mp6uJLgguEhv_TeE,2462
|
|
8
|
-
ltq/task.py,sha256=
|
|
9
|
-
ltq/worker.py,sha256=
|
|
10
|
-
ltq-0.1.
|
|
11
|
-
ltq-0.1.
|
|
12
|
-
ltq-0.1.
|
|
13
|
-
ltq-0.1.
|
|
8
|
+
ltq/task.py,sha256=JOeyulGJ-jSM_wzYyKPTPElRGx7Ncu6n1dRdn9NGwMI,1184
|
|
9
|
+
ltq/worker.py,sha256=PAMW8hvTuWCUALw41TnVBmcCxXytJbgVsxALAY9qmFY,3031
|
|
10
|
+
ltq-0.1.2.dist-info/WHEEL,sha256=XV0cjMrO7zXhVAIyyc8aFf1VjZ33Fen4IiJk5zFlC3g,80
|
|
11
|
+
ltq-0.1.2.dist-info/entry_points.txt,sha256=OogYaOJ_RORrWtrLlEL_gTN9Vx5tkgawl8BO7G9FKcg,38
|
|
12
|
+
ltq-0.1.2.dist-info/METADATA,sha256=7Mvz05MwsRJ5ddbegQofl9iLDHgELxwY2JEsSnJGK5Q,2316
|
|
13
|
+
ltq-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|