Description
Problem
aiohttp.ClientSession
is expensive to initialise and should be shared application-wide rather than re-created per request.
Description
In order to close the session we'll likely need to create a Gunicorn worker subclass that calls close
on the session (wrapped in async_to_sync
).
Follow the pattern from https://github.com/WordPress/openverse/blob/980ef96e0e16fc758f78be9f2aadf595f75948f6/api/api/utils/aiohttp.py for how to manage the session object and register its close.
Relevant before moving to ASGI Django because check_dead_links
already uses this and creates a new session per request rather than re-using one.
Once we move to ASGI Django, we'll be able to swap out the close handler out of the Gunicorn worker subclass and into the ASGI lifecycle as demonstrated in the linked example above.
Metadata
Assignees
Labels
Type
Projects
Status
✅ Done