Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting FastAPI 0.94.0 startup / shutdown events are decpricated #7

Open
quizmoon opened this issue Aug 21, 2023 · 5 comments · Fixed by #9
Open

Starting FastAPI 0.94.0 startup / shutdown events are decpricated #7

quizmoon opened this issue Aug 21, 2023 · 5 comments · Fixed by #9

Comments

@quizmoon
Copy link

Starting of FastAPI 0.94.0 the "startup / shutdown" events are deprecated and the "lifespan" has been introduced:
https://fastapi.tiangolo.com/advanced/events/#lifespan

Would be great to have support of "lifespan" in taskiq-fastapi or example how to avoid duplication of startup / shutdown calls.

@s3rius
Copy link
Member

s3rius commented Sep 2, 2023

Hi and thanks for noticing.

The startup|shutdown are not yet deprecated. We will use them untill it's deprecated, because it works. If it won't, we implement it.

@quizmoon
Copy link
Author

quizmoon commented Sep 2, 2023

Well, it is not removed, but deprecated:
Alternative Events (deprecated)

image

@s3rius
Copy link
Member

s3rius commented Sep 3, 2023

🤔 🤔 🤔 Okay. Probably it would be nice to implement.

@s3rius s3rius linked a pull request Oct 3, 2023 that will close this issue
@XChikuX
Copy link

XChikuX commented Apr 19, 2024

@s3rius Is the below method acceptable?

I think we need some updated docs

@asynccontextmanager
async def lifespan(app: FastAPI):
    # Load the FastAPI app
    log.info("[bold green blink]App is Starting Up![/]", extra={"markup": True})
    if not broker.is_worker_process:
        log.info("Starting TaskIQ broker")
        await broker.startup()
    yield

    log.info(
        "[bold blue blink]App is Shutting Down Gracefully![/]",
        extra={"markup": True},
    )
    if not broker.is_worker_process:
        log.info("Shutting down TaskIQ broker")
        await broker.shutdown()


app = FastAPI(title="❤️", lifespan=lifespan)

@s3rius
Copy link
Member

s3rius commented May 15, 2024

Sure thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants