Skip to content

Commit 8f01696

Browse files
committed
Update the docs and explicitly specify missing result error
1 parent b6a6ddf commit 8f01696

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

README.md

Lines changed: 9 additions & 2 deletions
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.

taskiq_redis/exceptions.py

Lines changed: 4 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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")
@@ -121,6 +122,9 @@ async def get_result( # noqa: WPS210
121122
name=task_id,
122123
)
123124

125+
if result_value is None:
126+
raise ResultIsMissingError()
127+
124128
taskiq_result: TaskiqResult[_ReturnType] = pickle.loads(result_value)
125129

126130
if not with_logs:

0 commit comments

Comments
 (0)