taskiq-python / taskiq-redis

Broker and result backend for taskiq
MIT License
35 stars 17 forks source link

Error while running your example #34

Open Emilianocm23 opened 1 year ago

Emilianocm23 commented 1 year ago

Hello, im using the same code as the example here on your docs, and i get an error.

Error:

taskiq_result: TaskiqResult[_ReturnType] = pickle.loads(result_value)
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: a bytes-like object is required, not 'NoneType'

The above exception was the direct cause of the following exception:

    raise ResultGetError() from exc
taskiq.exceptions.ResultGetError

Code:

import asyncio
from taskiq_redis import ListQueueBroker, RedisAsyncResultBackend

url = f'redis://default:passwordhere@myremoteserver.com:11131'

redis_async_result = RedisAsyncResultBackend(
    redis_url=url,
)
broker = ListQueueBroker(
    url=url,
    result_backend=redis_async_result,
)

@broker.task
async def best_task_ever() -> None:
    """Solve all problems in the world."""
    await asyncio.sleep(5.5)
    print("All problems are solved!")

async def main():
    task = await best_task_ever.kiq()
    print(await task.get_result())

asyncio.run(main())

I want to use the same redis database for tasks broker and results. (Like Django-Q) Im using python 3.11 I installed both taskiq and taskiq-redis modules. Thanks for making this library, it looks really promising.

s3rius commented 1 year ago

Hi, @Emilianocm23, and thanks for raising this issue. I guess the problem is that result is not ready yet.

I agree that the error is not obvious. We should definitely change it.

To solve this issue, you can use wait_result. It will wait for the result to be ready.

s3rius commented 1 year ago

I will keep this issue open until we make a new type of error for this particular edge case and update readme.

booqoffsky commented 1 year ago

@Emilianocm23 In addition, such error may appear if taskiq workers were not initially started. Just in case, here is how to run the workers: https://taskiq-python.github.io/guide/cli.html#worker

For your example, if the code file is named mycode.py, just run the command: taskiq worker mycode:broker

sminnee commented 1 month ago

FWIW it looks like this issue can be closed.