Skip to content

TypeError: BrokerWrapper.task.<locals>.<lambda>__taskiq_original() takes 0 positional arguments but 1 was given #78

@glambary

Description

@glambary
kafka_router = KafkaRouter(
    settings.kafka.KAFKA_BROKER,
    include_in_schema=True,
)

taskiq_broker = BrokerWrapper(kafka_router.broker)

taskiq_scheduler = TaskiqScheduler(
    broker=taskiq_broker,
    sources=[LabelScheduleSource(taskiq_broker)],
)

@taskiq_broker.task
async def sync_last_bets() -> None:
    td = timedelta(minutes=10, seconds=30)
    await sync_service.sync_bets(batch_size=100, time_delta=td)

I need to run the task once.

if i set @taskiq_broker.task exc that schedule parameter is required.
if I set it this way (@taskiq_broker.task(schedule=[{"cron": "0 0 31 2 *"}])) and try to run it manually in lifespan fastapi
bootstrap.py:

from broker.tasks import sync_bets_once
await sync_bets_once.kiq()

Exc:
File "/home/shakdevich/Dropbox/python/Funtech/scannerservice/project/core/bootstrap.py", line 34, in lifespan
await run_tasks()
File "/home/shakdevich/Dropbox/python/Funtech/scannerservice/project/core/bootstrap.py", line 75, in run_tasks
from broker.tasks import sync_init_bets
File "/home/shakdevich/Dropbox/python/Funtech/scannerservice/project/broker/tasks.py", line 24, in
@taskiq_broker.task(schedule=[{"0 0 31 2 *"}}])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/shakdevich/.cache/pypoetry/virtualenvs/scannerservice-Wg8Y1DKw-py3.12/lib/python3.12/site-packages/taskiq/decor.py", line 98, in call
return self.original_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: BrokerWrapper.task..__taskiq_original() takes 0 positional arguments but 1 was given

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions