I have a repeated task that runs every 15 minutes.
@app.on_event("startup")
@repeat_every(seconds=60 * 15, wait_first=True)
def myFunction(db=SessionLocal()) -> None:
test(db=db, for_test=False)
It works pretty normal at the beginning. But after some time (Like 5-6 hours) It stops working and never repeats task again. When I check logs in Cloud Run, I see this message;
RuntimeError: coroutine ignored GeneratorExit
Also such logs;
2022-09-29 10:04:04.263 EETTask was destroyed but it is pending!
2022-09-29 10:04:04.263 EETtask: <Task pending name='Task-850' coro=<H2Protocol.send_task() running at /usr/local/lib/python3.9/site-packages/hypercorn/protocol/h2.py:148> wait_for=<Future cancelled> cb=[_gather.<locals>._done_callback() at /usr/local/lib/python3.9/asyncio/tasks.py:767]>
I have to deploy a new revision to make repeated tasks work again. I'd like to know what to do in this situation and why this error occurs. It seems like there is no such problem in localhost.
Should I use Google Scheduler instead of FastApi utils' repeated tasks?
The problem was occuring because of my startup script.
I haven't noticed but i was using
--reloadtag in production. I can't believe this.After I edited my startup script for production, everything worked fine.