Miksus / rocketry-with-fastapi

Example of how to create a scheduler with an API
MIT License
88 stars 12 forks source link

Application does not close on ctrl+c #2

Open carlosporta opened 1 year ago

carlosporta commented 1 year ago

I am trying to kill the server and the rocketry app. But when I press ctrl+c only the server is killed. I am already using the custom class provided.

carlosporta commented 1 year ago
import asyncio
import logging

from api import app as app_fastapi
from scheduler import app as app_rocketry

@app_fastapi.on_event('startup')
async def on_startup():
    logger = logging.getLogger('rocketry.task')
    logger.addHandler(logging.StreamHandler())
    asyncio.create_task(app_rocketry.serve())

@app_fastapi.on_event('shutdown')
def on_shutdown():
    print('shutdown')
    app_rocketry.session.shut_down()

I change the main.py file to this.

Miksus commented 1 year ago

Thanks for noting this! I suppose this (the on_event) perhaps a feature made to FastAPI after I made the template. I have plans to update the template with the "bigger application setup" when I'm done with latest features of Rocketry. I'll add this then.