Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

must not use a script's none-relative path as entrypoint to run #329

Open
ryanrain2016 opened this issue Jun 3, 2024 · 1 comment
Open

Comments

@ryanrain2016
Copy link

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 "..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 ..taskiq_demo:add_one in my redis.
code in taskiq/abc/broker.py(line 317-322) produce the problem

@s3rius
Copy link
Member

s3rius commented Jun 11, 2024

So, it happens because the way tasknames generated. You can fix this issue by explicitly defining taskname in the decorator.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants