diff options
| author | 2019-12-19 14:32:28 +0000 | |
|---|---|---|
| committer | 2019-12-19 14:32:28 +0000 | |
| commit | ca525c6b84e221c7941946f1ff4c3795c3757008 (patch) | |
| tree | 53d19dc5499ff33db572d75b238d731d6acdbab5 | |
| parent | Make logging configurable through config file (diff) | |
| signature | ||
Support web server config changes
| -rw-r--r-- | http2irc.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/http2irc.py b/http2irc.py index 165aef1..1ead513 100644 --- a/http2irc.py +++ b/http2irc.py @@ -376,22 +376,26 @@ class WebServer: self._app.add_routes([aiohttp.web.post('/{path:.+}', self.post)]) self.update_config(config) + self._configChanged = asyncio.Event() def update_config(self, config): self._paths = {map_['webpath']: (map_['ircchannel'], f'Basic {base64.b64encode(map_["auth"].encode("utf-8")).decode("utf-8")}' if map_['auth'] else False) for map_ in config['maps'].values()} needRebind = self.config['web'] != config['web'] self.config = config if needRebind: - #TODO - logging.error('Webserver host or port changes while running are currently not supported') + self._configChanged.set() async def run(self, stopEvent): - runner = aiohttp.web.AppRunner(self._app) - await runner.setup() - site = aiohttp.web.TCPSite(runner, self.config['web']['host'], self.config['web']['port']) - await site.start() - await stopEvent.wait() - await runner.cleanup() + while True: + runner = aiohttp.web.AppRunner(self._app) + await runner.setup() + site = aiohttp.web.TCPSite(runner, self.config['web']['host'], self.config['web']['port']) + await site.start() + await asyncio.wait((stopEvent.wait(), self._configChanged.wait()), return_when = concurrent.futures.FIRST_COMPLETED) + await runner.cleanup() + if stopEvent.is_set(): + break + self._configChanged.clear() async def post(self, request): logging.info(f'Received request for {request.path!r}') |
