aboutsummaryrefslogtreecommitdiff
path: root/http2irc.py
diff options
context:
space:
mode:
authorGravatar JustAnotherArchivist2019-12-19 14:32:28 +0000
committerGravatar JustAnotherArchivist2019-12-19 14:32:28 +0000
commitca525c6b84e221c7941946f1ff4c3795c3757008 (patch)
tree53d19dc5499ff33db572d75b238d731d6acdbab5 /http2irc.py
parentMake logging configurable through config file (diff)
signature
Support web server config changes
Diffstat (limited to 'http2irc.py')
-rw-r--r--http2irc.py20
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}')