Skip to content

ASGI lifecycle events #187

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

Merged
merged 27 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a2ad67c
Yield a disconnect on the second receive call
tonybaloney Jan 11, 2022
d8fc213
Merge remote-tracking branch 'upstream/dev' into dev
tonybaloney May 23, 2022
b9cd37a
Merge branch 'Azure:dev' into dev
tonybaloney Oct 9, 2022
ad52ad5
Merge remote-tracking branch 'upstream/dev' into dev
tonybaloney Nov 1, 2022
e6c925c
Integrate ASGI startup and shutdown lifecycle events
tonybaloney Jul 18, 2023
be4dffd
Merge branch 'dev' into asgi_startup_lifecycles
tonybaloney Jul 18, 2023
734e2ac
Code cleanup
tonybaloney Jul 18, 2023
2083a48
Support startup and shutdown events. Capture failures. Use asyncio ev…
tonybaloney Jul 18, 2023
be386e5
Use debug
tonybaloney Jul 18, 2023
1efb812
Lint code and fix some tests
tonybaloney Jul 18, 2023
fc1f829
Run the shutdown as a task
tonybaloney Jul 18, 2023
1c8b7de
Use a type variable for the receive queue
tonybaloney Jul 18, 2023
ee1fadd
Direct imports
tonybaloney Jul 25, 2023
fb457ec
Initialize event loops
tonybaloney Jul 25, 2023
ca836de
Initialize queues and signals inside coroutines to ensure the same ev…
tonybaloney Jul 25, 2023
502b2ca
Test all sequences and events
tonybaloney Jul 25, 2023
246afd2
Verify sequence runtime error is thrown
tonybaloney Jul 25, 2023
c88123e
Check startup was called before calling destroy in __del__ magic
tonybaloney Jul 25, 2023
d4788fe
Will no longer execute requests if the startup failed, will retry.
tonybaloney Jul 25, 2023
60ae50f
Test more failure scenarios
tonybaloney Jul 25, 2023
d86c622
Merge branch 'dev' into asgi_startup_lifecycles
tonybaloney Jul 31, 2023
fe58fdf
Merge branch 'dev' into asgi_startup_lifecycles
tonybaloney Aug 7, 2023
7c129cf
Merge branch 'dev' into asgi_startup_lifecycles
tonybaloney Aug 31, 2023
1b88383
Merge branch 'dev' into asgi_startup_lifecycles
gavin-aguiar Sep 1, 2023
b94205a
Merge branch 'dev' into asgi_startup_lifecycles
tonybaloney Oct 24, 2023
8113f1b
Merge branch 'dev' into asgi_startup_lifecycles
vrdmr Nov 14, 2023
f083cf8
Merge branch 'dev' into asgi_startup_lifecycles
gavin-aguiar Nov 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Check startup was called before calling destroy in __del__ magic
  • Loading branch information
tonybaloney committed Jul 25, 2023
commit c88123ecd689eb18db31ca6d6ffa2d93bad1bf17
2 changes: 1 addition & 1 deletion azure/functions/_http_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ async def notify_startup(self):

async def notify_shutdown(self):
"""Notify the ASGI app that the server is shutting down."""
self._logger.debug("Notifying ASGI app of shutdown.")
if not self.lifespan_receive_queue or not self.lifespan_shutdown_event:
raise RuntimeError("notify_startup() must be called first.")

self._logger.debug("Notifying ASGI app of shutdown.")
shutdown_event = {"type": "lifespan.shutdown"}
await self.lifespan_receive_queue.put(shutdown_event)
await self.lifespan_shutdown_event.wait()
3 changes: 2 additions & 1 deletion azure/functions/decorators/function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,8 @@ def __init__(self, app,
self.startup_task_done = False

def __del__(self):
asyncio.run(self.middleware.notify_shutdown())
if self.startup_task_done:
asyncio.run(self.middleware.notify_shutdown())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why for shutdown, we dont raise runtimeerror if shutdown does not succeed (similar to startup)?


def _add_http_app(self,
http_middleware: Union[
Expand Down