File tree Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Expand file tree Collapse file tree 3 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ pip install taskiq-redis
1818Let's see the example with the redis broker and redis async result:
1919
2020``` python
21+ # broker.py
2122import asyncio
2223
2324from taskiq_redis import ListQueueBroker, RedisAsyncResultBackend
@@ -42,12 +43,18 @@ async def best_task_ever() -> None:
4243
4344async 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
5360We have two brokers with similar interfaces, but with different logic.
Original file line number Diff line number Diff line change @@ -8,3 +8,7 @@ class DuplicateExpireTimeSelectedError(TaskIQRedisError):
88
99class 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."""
Original file line number Diff line number Diff line change 88from 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 :
You can’t perform that action at this time.
0 commit comments