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

Add lifespan middleware #1676

Merged
merged 2 commits into from Mar 23, 2023
Merged

Add lifespan middleware #1676

merged 2 commits into from Mar 23, 2023

Conversation

RobbeSneyders
Copy link
Member

This PR adds a new middleware to handle lifespan events.

I added this as a separate middleware so it is encapsulated and aligned for both the FlaskApp and AsyncApp. It leverages a Starlette Router to register and call the lifespan handler.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 4410472221

  • 25 of 25 (100.0%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 93.398%

Totals Coverage Status
Change from base Build 4410156717: 0.03%
Covered Lines: 3296
Relevant Lines: 3529

💛 - Coveralls

@Ruwann
Copy link
Member

Ruwann commented Mar 21, 2023

What is the reason for treating this separately from the other middlewares? Why not make it part of the list of middlewares?

@RobbeSneyders
Copy link
Member Author

It is part of the list of middlewares. But you still pass in a handler which the middleware will use.

The biggest difference between the LifespanMiddleware and the other middlewares, is that this one is configured on the App level, instead of the API level. This is why the arguments are passed when instantiating the middleware instead of via the add_api method.

It would have been great to align this with the other middlewares, but Starlette currently doesn't support lifespans for nested Apps / Routers, which is the equivalent of our APIs.

@RobbeSneyders RobbeSneyders merged commit 79c0852 into main Mar 23, 2023
@RobbeSneyders RobbeSneyders deleted the feature/lifespan branch March 23, 2023 18:11
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 this pull request may close these issues.

None yet

3 participants