diff --git a/ahserver/configuredServer.py b/ahserver/configuredServer.py index 0e01307..44a68d2 100644 --- a/ahserver/configuredServer.py +++ b/ahserver/configuredServer.py @@ -22,6 +22,15 @@ from .filestorage import TmpFileRecord from .loadplugins import load_plugins from .real_ip import real_ip_middleware +startup_coros = [] +cleanup_coros = [] + +def add_startup(coro): + startup_coros.append(coro) + +def add_cleanup(coro): + cleanup_coros.append(coro) + class AHApp(web.Application): def __init__(self, *args, **kw): if not kw.get('client_max_size'): @@ -30,7 +39,9 @@ class AHApp(web.Application): super().__init__(*args, **kw) self.user_data = DictObject() self.middlewares.insert(0, real_ip_middleware()) - + [ self.on_startup.append(c) for c in startup_coros ] + [ self.on_cleanup.append(c) for c in cleanup_coros ] + def set_data(self, k, v): self.user_data[k] = v