fastapi-alembic-sqlmodel-async icon indicating copy to clipboard operation
fastapi-alembic-sqlmodel-async copied to clipboard

Task completed but still shows pending

Open russell310 opened this issue 2 years ago • 2 comments

celery.conf.update({
    "beat_dburi": settings.SYNC_CELERY_BEAT_DATABASE_URI,
    'beat_schedule': {
        'run-periodic-task-every-60-seconds': {
            'task': 'tasks.periodic',
            'schedule': timedelta(seconds=10),
        },
    }
})
async def get_hero(hero_id: UUID) -> list[HeroRead]:
    async with SessionLocal() as session:
        await asyncio.sleep(5)
        hero = await crud.hero.get(id=hero_id, db_session=session)
        return hero


@celery.task(name="tasks.periodic")
def periodic_task_example() -> None:
    try:
        hero = runnify(get_hero)(hero_id=UUID('b4cd39a6-0d89-44b6-b439-96a92a0fbdb6'))
        return hero.id
    except Exception as e:
        print(e)

For the 1st time get data successfully. After then it shows Task <Task pending name='functools' coro=<run..wrapper()> How to solve this issue?

russell310 avatar Nov 04 '23 23:11 russell310

Hello @russell310 that is weird I am going to check it

jonra1993 avatar Nov 14 '23 00:11 jonra1993

Was this issue ever solved?

vcnwafor avatar Feb 03 '24 05:02 vcnwafor

Hello @russell310 and @vcnwafor the bug was solved here https://github.com/jonra1993/fastapi-alembic-sqlmodel-async/issues/94. using asyncio.get_event_loop().run_until_complete() instead of runnify.

jonra1993 avatar Apr 01 '24 04:04 jonra1993