taskiq-python / taskiq-redis

Broker and result backend for taskiq
MIT License
40 stars 18 forks source link

task with a wrong taskname on python 3.10.1 windows #60

Closed ryanrain2016 closed 5 months ago

ryanrain2016 commented 5 months ago

taskiq_demo.py如下

import asyncio

from taskiq_redis import ListQueueBroker, RedisAsyncResultBackend

redis_dsn = 'xxxx'
broker = ListQueueBroker(redis_dsn, queue_name='taskiq:req').with_result_backend(
    RedisAsyncResultBackend(redis_dsn)
)

@broker.task
async def add_one(value: int) -> int:
    print(value, '#' * 20)
    return value + 1

async def main() -> None:
    # Never forget to call startup in the beginning.
    await broker.startup()
    # Send the task to the broker.
    task = await add_one.kiq(1)
    # Wait for the result.
    result = await task.wait_result(timeout=5)
    print(f"Task execution took: {result.execution_time} seconds.")
    if not result.is_err:
        print(f"Returned value: {result.return_value}")
    else:
        print("Error found while executing task.")
    await broker.shutdown()
if __name__ == "__main__":
    asyncio.run(main())

run the command to start worker

taskiq worker taskiq_demo:broker

run the command to run the program

python taskiq_demo.py

then i get a output task "c:.Users.ryan.Documents.bak.project.python.taskiq_demo.taskiq_demo:add_one" is not found. Maybe you forgot to import it? when I stop the taskiq window and run the script again, I get a task with name c:.Users.ryan.Documents.bak.project.python.taskiq_demo.taskiq_demo:add_one in my redis. I've tried running the same script on linux with python 3.9.5. it works well.

ryanrain2016 commented 5 months ago

I know what the difference is. I use vscode run the script in windows. when I use python taskiq_demo.py. I got a task "..taskiq_demo:add_one" is not found. Maybe you forgot to import it?

ryanrain2016 commented 5 months ago

discuss on taskiq'issue, close this

s3rius commented 5 months ago

Easiest solution would be to add task_name parameter to the decorator so the name will always be the same.