taskiq-redis 0.5.2__py3-none-any.whl → 0.5.4__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.
- taskiq_redis/__init__.py +2 -0
- taskiq_redis/redis_cluster_broker.py +67 -0
- taskiq_redis/schedule_source.py +3 -3
- {taskiq_redis-0.5.2.dist-info → taskiq_redis-0.5.4.dist-info}/METADATA +2 -2
- taskiq_redis-0.5.4.dist-info/RECORD +11 -0
- taskiq_redis-0.5.2.dist-info/RECORD +0 -10
- {taskiq_redis-0.5.2.dist-info → taskiq_redis-0.5.4.dist-info}/WHEEL +0 -0
taskiq_redis/__init__.py
CHANGED
|
@@ -4,6 +4,7 @@ from taskiq_redis.redis_backend import (
|
|
|
4
4
|
RedisAsyncResultBackend,
|
|
5
5
|
)
|
|
6
6
|
from taskiq_redis.redis_broker import ListQueueBroker, PubSubBroker
|
|
7
|
+
from taskiq_redis.redis_cluster_broker import ListQueueClusterBroker
|
|
7
8
|
from taskiq_redis.schedule_source import RedisScheduleSource
|
|
8
9
|
|
|
9
10
|
__all__ = [
|
|
@@ -11,5 +12,6 @@ __all__ = [
|
|
|
11
12
|
"RedisAsyncResultBackend",
|
|
12
13
|
"ListQueueBroker",
|
|
13
14
|
"PubSubBroker",
|
|
15
|
+
"ListQueueClusterBroker",
|
|
14
16
|
"RedisScheduleSource",
|
|
15
17
|
]
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from typing import Any, AsyncGenerator
|
|
2
|
+
|
|
3
|
+
from redis.asyncio import RedisCluster
|
|
4
|
+
from taskiq.abc.broker import AsyncBroker
|
|
5
|
+
from taskiq.message import BrokerMessage
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BaseRedisClusterBroker(AsyncBroker):
|
|
9
|
+
"""Base broker that works with Redis Cluster."""
|
|
10
|
+
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
url: str,
|
|
14
|
+
queue_name: str = "taskiq",
|
|
15
|
+
max_connection_pool_size: int = 2**31,
|
|
16
|
+
**connection_kwargs: Any,
|
|
17
|
+
) -> None:
|
|
18
|
+
"""
|
|
19
|
+
Constructs a new broker.
|
|
20
|
+
|
|
21
|
+
:param url: url to redis.
|
|
22
|
+
:param queue_name: name for a list in redis.
|
|
23
|
+
:param max_connection_pool_size: maximum number of connections in pool.
|
|
24
|
+
:param connection_kwargs: additional arguments for aio-redis ConnectionPool.
|
|
25
|
+
"""
|
|
26
|
+
super().__init__()
|
|
27
|
+
|
|
28
|
+
self.redis: RedisCluster[bytes] = RedisCluster.from_url(
|
|
29
|
+
url=url,
|
|
30
|
+
max_connections=max_connection_pool_size,
|
|
31
|
+
**connection_kwargs,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
self.queue_name = queue_name
|
|
35
|
+
|
|
36
|
+
async def shutdown(self) -> None:
|
|
37
|
+
"""Closes redis connection pool."""
|
|
38
|
+
await self.redis.aclose() # type: ignore[attr-defined]
|
|
39
|
+
await super().shutdown()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class ListQueueClusterBroker(BaseRedisClusterBroker):
|
|
43
|
+
"""Broker that works with Redis Cluster and distributes tasks between workers."""
|
|
44
|
+
|
|
45
|
+
async def kick(self, message: BrokerMessage) -> None:
|
|
46
|
+
"""
|
|
47
|
+
Put a message in a list.
|
|
48
|
+
|
|
49
|
+
This method appends a message to the list of all messages.
|
|
50
|
+
|
|
51
|
+
:param message: message to append.
|
|
52
|
+
"""
|
|
53
|
+
await self.redis.lpush(self.queue_name, message.message) # type: ignore[attr-defined]
|
|
54
|
+
|
|
55
|
+
async def listen(self) -> AsyncGenerator[bytes, None]:
|
|
56
|
+
"""
|
|
57
|
+
Listen redis queue for new messages.
|
|
58
|
+
|
|
59
|
+
This function listens to the queue
|
|
60
|
+
and yields new messages if they have BrokerMessage type.
|
|
61
|
+
|
|
62
|
+
:yields: broker messages.
|
|
63
|
+
"""
|
|
64
|
+
redis_brpop_data_position = 1
|
|
65
|
+
while True:
|
|
66
|
+
value = await self.redis.brpop([self.queue_name]) # type: ignore[attr-defined]
|
|
67
|
+
yield value[redis_brpop_data_position]
|
taskiq_redis/schedule_source.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import dataclasses
|
|
2
1
|
from typing import Any, List, Optional
|
|
3
2
|
|
|
4
3
|
from redis.asyncio import ConnectionPool, Redis
|
|
5
4
|
from taskiq import ScheduleSource
|
|
6
5
|
from taskiq.abc.serializer import TaskiqSerializer
|
|
6
|
+
from taskiq.compat import model_dump, model_validate
|
|
7
7
|
from taskiq.scheduler.scheduled_task import ScheduledTask
|
|
8
8
|
|
|
9
9
|
from taskiq_redis.serializer import PickleSerializer
|
|
@@ -60,7 +60,7 @@ class RedisScheduleSource(ScheduleSource):
|
|
|
60
60
|
async with Redis(connection_pool=self.connection_pool) as redis:
|
|
61
61
|
await redis.set(
|
|
62
62
|
f"{self.prefix}:{schedule.schedule_id}",
|
|
63
|
-
self.serializer.dumpb(
|
|
63
|
+
self.serializer.dumpb(model_dump(schedule)),
|
|
64
64
|
)
|
|
65
65
|
|
|
66
66
|
async def get_schedules(self) -> List[ScheduledTask]:
|
|
@@ -82,7 +82,7 @@ class RedisScheduleSource(ScheduleSource):
|
|
|
82
82
|
if buffer:
|
|
83
83
|
schedules.extend(await redis.mget(buffer))
|
|
84
84
|
return [
|
|
85
|
-
ScheduledTask
|
|
85
|
+
model_validate(ScheduledTask, self.serializer.loadb(schedule))
|
|
86
86
|
for schedule in schedules
|
|
87
87
|
if schedule
|
|
88
88
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: taskiq-redis
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.4
|
|
4
4
|
Summary: Redis integration for taskiq
|
|
5
5
|
Home-page: https://github.com/taskiq-python/taskiq-redis
|
|
6
6
|
Keywords: taskiq,tasks,distributed,async,redis,result_backend
|
|
@@ -16,7 +16,7 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
16
16
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.8
|
|
18
18
|
Requires-Dist: redis (>=5,<6)
|
|
19
|
-
Requires-Dist: taskiq (>=0.10.
|
|
19
|
+
Requires-Dist: taskiq (>=0.10.3,<1)
|
|
20
20
|
Project-URL: Repository, https://github.com/taskiq-python/taskiq-redis
|
|
21
21
|
Description-Content-Type: text/markdown
|
|
22
22
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
taskiq_redis/__init__.py,sha256=sPv4uLLPSPc8zXK42puvsSMDY5HwbCePdJheYylyApg,527
|
|
2
|
+
taskiq_redis/exceptions.py,sha256=eS4bfZVAjyMsnFs3IF74uYwO1KZOlrYxhxgPqD49ztU,561
|
|
3
|
+
taskiq_redis/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
taskiq_redis/redis_backend.py,sha256=Q_pJ1Bz-NpTyFT68UswBvsNYWkLtnSPF1x8QbOnbWI0,8357
|
|
5
|
+
taskiq_redis/redis_broker.py,sha256=qQLWWvY-NacVXkgDGVCe2fyWYPkjZiOnggB0hpPStqw,3957
|
|
6
|
+
taskiq_redis/redis_cluster_broker.py,sha256=CgPKkoEHZ1moNM-VNmzPQdjjNOrhiVUCNV-7FrUgqTo,2121
|
|
7
|
+
taskiq_redis/schedule_source.py,sha256=SWMGC3limXRgyxZS5BawnF3bHGgJpjljByIUL5nC2BY,3414
|
|
8
|
+
taskiq_redis/serializer.py,sha256=x-1ExYoD_EnDiM53lyvI99MdTpNj_pORMIaCL07-6nU,416
|
|
9
|
+
taskiq_redis-0.5.4.dist-info/METADATA,sha256=XKrSxYM3F5RkGwX5mb-HGxertnZWeBpf1f_9c_yaYPQ,3588
|
|
10
|
+
taskiq_redis-0.5.4.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
11
|
+
taskiq_redis-0.5.4.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
taskiq_redis/__init__.py,sha256=zOtK-dJNXBdZ_kh91Otef9ayrHLxwFz0_J78conkl2Q,428
|
|
2
|
-
taskiq_redis/exceptions.py,sha256=eS4bfZVAjyMsnFs3IF74uYwO1KZOlrYxhxgPqD49ztU,561
|
|
3
|
-
taskiq_redis/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
taskiq_redis/redis_backend.py,sha256=Q_pJ1Bz-NpTyFT68UswBvsNYWkLtnSPF1x8QbOnbWI0,8357
|
|
5
|
-
taskiq_redis/redis_broker.py,sha256=qQLWWvY-NacVXkgDGVCe2fyWYPkjZiOnggB0hpPStqw,3957
|
|
6
|
-
taskiq_redis/schedule_source.py,sha256=7AdY7394wm0UEPCn7ovT4vpKjSLXTw7EUgdU5rGJEaY,3374
|
|
7
|
-
taskiq_redis/serializer.py,sha256=x-1ExYoD_EnDiM53lyvI99MdTpNj_pORMIaCL07-6nU,416
|
|
8
|
-
taskiq_redis-0.5.2.dist-info/METADATA,sha256=aduzmIACwufrf_Wyqx8nHp1eDDAl6Qea3jIifZk0TIg,3588
|
|
9
|
-
taskiq_redis-0.5.2.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
10
|
-
taskiq_redis-0.5.2.dist-info/RECORD,,
|
|
File without changes
|