diff --git a/CHANGES/2988.feature b/CHANGES/2988.feature new file mode 100644 index 00000000000..f9b76fd6ced --- /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 73ba6e38f69..07e3d8347a4 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):