From 4816ee99b47f8848767ed193fee1a860ff9822ed Mon Sep 17 00:00:00 2001 From: Brian Bouterse Date: Mon, 27 Apr 2020 16:56:00 -0400 Subject: [PATCH] GunicornWebWorker subclasses can config AppRunner Currently there is no way to configure the Application Runner created by the `aiohttp.GunicornWebWorker`. This allows `GunicornWebWorker` subclasses to configure its `ApplicationRunner` by introducing the `GunicornWebWorker._get_application_runner_instance` method. --- CHANGES/2988.feature | 2 ++ aiohttp/worker.py | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 CHANGES/2988.feature diff --git a/CHANGES/2988.feature b/CHANGES/2988.feature new file mode 100644 index 0000000000..f9b76fd6ce --- /dev/null +++ b/CHANGES/2988.feature @@ -0,0 +1,2 @@ +Allow `GunicornWebWorker` subclasses to configure its `ApplicationRunner` by introducing the +`GunicornWebWorker._get_application_runner_instance` method. diff --git a/aiohttp/worker.py b/aiohttp/worker.py index 73ba6e38f6..07e3d8347a 100644 --- a/aiohttp/worker.py +++ b/aiohttp/worker.py @@ -73,13 +73,7 @@ async def _run(self) -> None: raise RuntimeError("wsgi app should be either Application or " "async function returning Application, got {}" .format(self.wsgi)) - access_log = self.log.access_log if self.cfg.accesslog else None - runner = web.AppRunner(app, - logger=self.log, - keepalive_timeout=self.cfg.keepalive, - access_log=access_log, - access_log_format=self._get_valid_log_format( - self.cfg.access_log_format)) + runner = self._get_application_runner_instance(app) await runner.setup() ctx = self._create_ssl_context(self.cfg) if self.cfg.is_ssl else None @@ -207,6 +201,17 @@ def _get_valid_log_format(self, source_format: str) -> str: else: return source_format + def _get_application_runner_instance(self, app, **kwargs): + access_log = self.log.access_log if self.cfg.accesslog else None + runner = web.AppRunner(app, + logger=self.log, + keepalive_timeout=self.cfg.keepalive, + access_log=access_log, + access_log_format=self._get_valid_log_format( + self.cfg.access_log_format), + **kwargs) + return runner + class GunicornUVLoopWebWorker(GunicornWebWorker):