Skip to content

Commit 8d15da7

Browse files
committed
Merge branch 'release/0.3.1'
2 parents 01a5b96 + fb6fac4 commit 8d15da7

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pip install taskiq-redis
1818
Let's see the example with the redis broker and redis async result:
1919

2020
```python
21+
# broker.py
2122
import asyncio
2223

2324
from taskiq_redis import ListQueueBroker, RedisAsyncResultBackend
@@ -42,12 +43,18 @@ async def best_task_ever() -> None:
4243

4344
async def main():
4445
task = await best_task_ever.kiq()
45-
print(await task.get_result())
46+
print(await task.wait_result())
4647

4748

48-
asyncio.run(main())
49+
if __name__ == "__main__":
50+
asyncio.run(main())
4951
```
5052

53+
Launch the workers:
54+
`taskiq worker broker:broker`
55+
Then run the main code:
56+
`python3 broker.py`
57+
5158
## PubSubBroker and ListQueueBroker configuration
5259

5360
We have two brokers with similar interfaces, but with different logic.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "taskiq-redis"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
description = "Redis integration for taskiq"
55
authors = ["taskiq-team <[email protected]>"]
66
readme = "README.md"

taskiq_redis/exceptions.py

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ class DuplicateExpireTimeSelectedError(TaskIQRedisError):
88

99
class ExpireTimeMustBeMoreThanZeroError(TaskIQRedisError):
1010
"""Error if two lifetimes are less or equal zero."""
11+
12+
13+
class ResultIsMissingError(TaskIQRedisError):
14+
"""Error if there is no result when trying to get it."""

taskiq_redis/redis_backend.py

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from taskiq_redis.exceptions import (
99
DuplicateExpireTimeSelectedError,
1010
ExpireTimeMustBeMoreThanZeroError,
11+
ResultIsMissingError,
1112
)
1213

1314
_ReturnType = TypeVar("_ReturnType")
@@ -109,6 +110,7 @@ async def get_result( # noqa: WPS210
109110
110111
:param task_id: task's id.
111112
:param with_logs: if True it will download task's logs.
113+
:raises ResultIsMissingError: if there is no result when trying to get it.
112114
:return: task's return value.
113115
"""
114116
async with Redis(connection_pool=self.redis_pool) as redis:
@@ -121,6 +123,9 @@ async def get_result( # noqa: WPS210
121123
name=task_id,
122124
)
123125

126+
if result_value is None:
127+
raise ResultIsMissingError()
128+
124129
taskiq_result: TaskiqResult[_ReturnType] = pickle.loads(result_value)
125130

126131
if not with_logs:

tests/test_backend.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from taskiq_redis.exceptions import (
1010
DuplicateExpireTimeSelectedError,
1111
ExpireTimeMustBeMoreThanZeroError,
12+
ResultIsMissingError,
1213
)
1314

1415
_ReturnType = TypeVar("_ReturnType")
@@ -210,7 +211,7 @@ async def test_unsuccess_backend_expire_ex_param(
210211
)
211212
await asyncio.sleep(1.1)
212213

213-
with pytest.raises(TypeError):
214+
with pytest.raises(ResultIsMissingError):
214215
await backend.get_result(task_id=task_id)
215216

216217

@@ -270,5 +271,5 @@ async def test_unsuccess_backend_expire_px_param(
270271
)
271272
await asyncio.sleep(1.1)
272273

273-
with pytest.raises(TypeError):
274+
with pytest.raises(ResultIsMissingError):
274275
await backend.get_result(task_id=task_id)

0 commit comments

Comments
 (0)