diff --git a/pyslackersweb/__init__.py b/pyslackersweb/__init__.py index bb0142a8..9944d82f 100644 --- a/pyslackersweb/__init__.py +++ b/pyslackersweb/__init__.py @@ -11,7 +11,7 @@ from sentry_sdk.integrations.aiohttp import AioHttpIntegration from sentry_sdk.integrations.logging import LoggingIntegration -from .contexts import background_jobs, client_session +from .contexts import background_jobs, client_session, slack_client from .filters import formatted_number from .middleware import request_context_middleware from .views import routes # , on_oauth2_login @@ -60,6 +60,7 @@ async def app_factory() -> web.Application: ) app.cleanup_ctx.append(client_session) + app.cleanup_ctx.append(slack_client) app.cleanup_ctx.append(background_jobs) app.add_routes(routes) diff --git a/pyslackersweb/contexts.py b/pyslackersweb/contexts.py index 79585b46..4e519bf2 100644 --- a/pyslackersweb/contexts.py +++ b/pyslackersweb/contexts.py @@ -34,5 +34,9 @@ async def background_jobs(app: web.Application) -> None: async def client_session(app: web.Application) -> None: async with ClientSession(raise_for_status=True) as session: app["client_session"] = session - app["slack_client"] = SlackAPI(token=app["slack_token"], session=session) yield + + +async def slack_client(app: web.Application) -> None: + app["slack_client"] = SlackAPI(token=app["slack_token"], session=app["client_session"]) + yield