taskiq-redis 0.5.3__py3-none-any.whl → 0.5.5__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
CHANGED
|
@@ -5,7 +5,10 @@ from taskiq_redis.redis_backend import (
|
|
|
5
5
|
)
|
|
6
6
|
from taskiq_redis.redis_broker import ListQueueBroker, PubSubBroker
|
|
7
7
|
from taskiq_redis.redis_cluster_broker import ListQueueClusterBroker
|
|
8
|
-
from taskiq_redis.schedule_source import
|
|
8
|
+
from taskiq_redis.schedule_source import (
|
|
9
|
+
RedisClusterScheduleSource,
|
|
10
|
+
RedisScheduleSource,
|
|
11
|
+
)
|
|
9
12
|
|
|
10
13
|
__all__ = [
|
|
11
14
|
"RedisAsyncClusterResultBackend",
|
|
@@ -14,4 +17,5 @@ __all__ = [
|
|
|
14
17
|
"PubSubBroker",
|
|
15
18
|
"ListQueueClusterBroker",
|
|
16
19
|
"RedisScheduleSource",
|
|
20
|
+
"RedisClusterScheduleSource",
|
|
17
21
|
]
|
taskiq_redis/schedule_source.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import dataclasses
|
|
2
1
|
from typing import Any, List, Optional
|
|
3
2
|
|
|
4
|
-
from redis.asyncio import ConnectionPool, Redis
|
|
3
|
+
from redis.asyncio import ConnectionPool, Redis, RedisCluster
|
|
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
|
]
|
|
@@ -95,3 +95,82 @@ class RedisScheduleSource(ScheduleSource):
|
|
|
95
95
|
async def shutdown(self) -> None:
|
|
96
96
|
"""Shut down the schedule source."""
|
|
97
97
|
await self.connection_pool.disconnect()
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class RedisClusterScheduleSource(ScheduleSource):
|
|
101
|
+
"""
|
|
102
|
+
Source of schedules for redis cluster.
|
|
103
|
+
|
|
104
|
+
This class allows you to store schedules in redis.
|
|
105
|
+
Also it supports dynamic schedules.
|
|
106
|
+
|
|
107
|
+
:param url: url to redis cluster.
|
|
108
|
+
:param prefix: prefix for redis schedule keys.
|
|
109
|
+
:param buffer_size: buffer size for redis scan.
|
|
110
|
+
This is how many keys will be fetched at once.
|
|
111
|
+
:param max_connection_pool_size: maximum number of connections in pool.
|
|
112
|
+
:param serializer: serializer for data.
|
|
113
|
+
:param connection_kwargs: additional arguments for RedisCluster.
|
|
114
|
+
"""
|
|
115
|
+
|
|
116
|
+
def __init__(
|
|
117
|
+
self,
|
|
118
|
+
url: str,
|
|
119
|
+
prefix: str = "schedule",
|
|
120
|
+
buffer_size: int = 50,
|
|
121
|
+
serializer: Optional[TaskiqSerializer] = None,
|
|
122
|
+
**connection_kwargs: Any,
|
|
123
|
+
) -> None:
|
|
124
|
+
self.prefix = prefix
|
|
125
|
+
self.redis: RedisCluster[bytes] = RedisCluster.from_url(
|
|
126
|
+
url,
|
|
127
|
+
**connection_kwargs,
|
|
128
|
+
)
|
|
129
|
+
self.buffer_size = buffer_size
|
|
130
|
+
if serializer is None:
|
|
131
|
+
serializer = PickleSerializer()
|
|
132
|
+
self.serializer = serializer
|
|
133
|
+
|
|
134
|
+
async def delete_schedule(self, schedule_id: str) -> None:
|
|
135
|
+
"""Remove schedule by id."""
|
|
136
|
+
await self.redis.delete(f"{self.prefix}:{schedule_id}") # type: ignore[attr-defined]
|
|
137
|
+
|
|
138
|
+
async def add_schedule(self, schedule: ScheduledTask) -> None:
|
|
139
|
+
"""
|
|
140
|
+
Add schedule to redis.
|
|
141
|
+
|
|
142
|
+
:param schedule: schedule to add.
|
|
143
|
+
:param schedule_id: schedule id.
|
|
144
|
+
"""
|
|
145
|
+
await self.redis.set( # type: ignore[attr-defined]
|
|
146
|
+
f"{self.prefix}:{schedule.schedule_id}",
|
|
147
|
+
self.serializer.dumpb(model_dump(schedule)),
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
async def get_schedules(self) -> List[ScheduledTask]:
|
|
151
|
+
"""
|
|
152
|
+
Get all schedules from redis.
|
|
153
|
+
|
|
154
|
+
This method is used by scheduler to get all schedules.
|
|
155
|
+
|
|
156
|
+
:return: list of schedules.
|
|
157
|
+
"""
|
|
158
|
+
schedules = []
|
|
159
|
+
buffer = []
|
|
160
|
+
async for key in self.redis.scan_iter(f"{self.prefix}:*"): # type: ignore[attr-defined]
|
|
161
|
+
buffer.append(key)
|
|
162
|
+
if len(buffer) >= self.buffer_size:
|
|
163
|
+
schedules.extend(await self.redis.mget(buffer)) # type: ignore[attr-defined]
|
|
164
|
+
buffer = []
|
|
165
|
+
if buffer:
|
|
166
|
+
schedules.extend(await self.redis.mget(buffer)) # type: ignore[attr-defined]
|
|
167
|
+
return [
|
|
168
|
+
model_validate(ScheduledTask, self.serializer.loadb(schedule))
|
|
169
|
+
for schedule in schedules
|
|
170
|
+
if schedule
|
|
171
|
+
]
|
|
172
|
+
|
|
173
|
+
async def post_send(self, task: ScheduledTask) -> None:
|
|
174
|
+
"""Delete a task after it's completed."""
|
|
175
|
+
if task.time is not None:
|
|
176
|
+
await self.delete_schedule(task.schedule_id)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: taskiq-redis
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.5
|
|
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
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
taskiq_redis/__init__.py,sha256=
|
|
1
|
+
taskiq_redis/__init__.py,sha256=fMdXYxulcaKur66UUlmqAQf_q24jT5UHDYsMYP6J4fw,602
|
|
2
2
|
taskiq_redis/exceptions.py,sha256=eS4bfZVAjyMsnFs3IF74uYwO1KZOlrYxhxgPqD49ztU,561
|
|
3
3
|
taskiq_redis/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
taskiq_redis/redis_backend.py,sha256=Q_pJ1Bz-NpTyFT68UswBvsNYWkLtnSPF1x8QbOnbWI0,8357
|
|
5
5
|
taskiq_redis/redis_broker.py,sha256=qQLWWvY-NacVXkgDGVCe2fyWYPkjZiOnggB0hpPStqw,3957
|
|
6
6
|
taskiq_redis/redis_cluster_broker.py,sha256=CgPKkoEHZ1moNM-VNmzPQdjjNOrhiVUCNV-7FrUgqTo,2121
|
|
7
|
-
taskiq_redis/schedule_source.py,sha256=
|
|
7
|
+
taskiq_redis/schedule_source.py,sha256=kFJP4418JwhqzhOMoP98EIaLNYGFvQWLKtlNUU0EvsY,6166
|
|
8
8
|
taskiq_redis/serializer.py,sha256=x-1ExYoD_EnDiM53lyvI99MdTpNj_pORMIaCL07-6nU,416
|
|
9
|
-
taskiq_redis-0.5.
|
|
10
|
-
taskiq_redis-0.5.
|
|
11
|
-
taskiq_redis-0.5.
|
|
9
|
+
taskiq_redis-0.5.5.dist-info/METADATA,sha256=5GSOGw4oUTeMojhu9IpIz6ZeEkqbIFrdqcMUbIaQbv4,3588
|
|
10
|
+
taskiq_redis-0.5.5.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
11
|
+
taskiq_redis-0.5.5.dist-info/RECORD,,
|
|
File without changes
|