-
Notifications
You must be signed in to change notification settings - Fork 180
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
The @repeat_every()
decorator does not trigger the function it decorates unless the @app.on_event('startup')
decorator is also present.
To Reproduce
I created this sample main.py
to show the issue I've been seeing.
- Copy the below and run
python3 main.py
. The app will create a local filetest.txt
and write a Unix timestamp to it every second. - Stop the app and comment out
@app.on_event('startup')
- Run the app again. The file
test.txt
is no longer being updated. If you delete this file and restart the app, it will never be created.
import time
from fastapi import FastAPI
from fastapi_utils.tasks import repeat_every
import uvicorn
app = FastAPI()
@app.on_event('startup')
@repeat_every(seconds=1)
def do_something():
with open('test.txt', 'w') as f:
f.write(f"{time.time():.0f}")
if __name__ == '__main__':
uvicorn.run('main:app')
Expected behavior
The function do_something()
should be writing to the file every 1 second, even with @app.on_event('startup')
commented out.
Environment:
- OS: Windows 10
- FastAPI Utils: 0.2.1
- FastAPI: 0.75.0
- Pydantic: 1.9.0
- Python: 3.10.4
vkomodey, mvoitko, sodik82, sagdusmir, fingoldo and 4 more
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working