add on_pause() and on_resume() for module - use in rest_api.py
This commit is contained in:
parent
754269576a
commit
bcdffacab5
2 changed files with 26 additions and 6 deletions
|
@ -175,17 +175,27 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
self.httpd = None
|
||||
if self.bot.get_setting("rest-api", False):
|
||||
port = int(self.bot.config.get("api-port", str(DEFAULT_PORT)))
|
||||
self.httpd = BitBotIPv6HTTPd(("::1", port), Handler)
|
||||
self._start_httpd()
|
||||
|
||||
self.thread = threading.Thread(target=self.httpd.serve_forever)
|
||||
self.thread.daemon = True
|
||||
self.thread.start()
|
||||
def _start_httpd(self):
|
||||
port = int(self.bot.config.get("api-port", str(DEFAULT_PORT)))
|
||||
self.httpd = BitBotIPv6HTTPd(("::1", port), Handler)
|
||||
|
||||
def unload(self):
|
||||
self.thread = threading.Thread(target=self.httpd.serve_forever)
|
||||
self.thread.daemon = True
|
||||
self.thread.start()
|
||||
def _stop_httpd(self):
|
||||
if self.httpd:
|
||||
self.httpd.shutdown()
|
||||
|
||||
def on_resume(self):
|
||||
self._start_httpd()
|
||||
|
||||
def unload(self):
|
||||
self._stop_httpd()
|
||||
def on_pause(self):
|
||||
self._stop_httpd()
|
||||
|
||||
@utils.hook("received.command.apikey")
|
||||
@utils.kwarg("private_only", True)
|
||||
@utils.kwarg("min_args", 1)
|
||||
|
|
|
@ -60,6 +60,11 @@ class BaseModule(object):
|
|||
def unload(self):
|
||||
pass
|
||||
|
||||
def on_pause(self):
|
||||
pass
|
||||
def on_resume(self):
|
||||
pass
|
||||
|
||||
def command_line(self, args: str):
|
||||
pass
|
||||
|
||||
|
@ -381,6 +386,9 @@ class ModuleManager(object):
|
|||
old_modules = self.modules
|
||||
self.modules = {}
|
||||
|
||||
for module in old_modules.values():
|
||||
module.module.on_pause()
|
||||
|
||||
failed = None
|
||||
for definition in loadable:
|
||||
try:
|
||||
|
@ -393,6 +401,8 @@ class ModuleManager(object):
|
|||
for module in self.modules.values():
|
||||
self._unload_module(module)
|
||||
self.modules = old_modules
|
||||
for module in old_modules.values():
|
||||
module.module.on_resume()
|
||||
|
||||
definition, exception = failed
|
||||
return TryReloadResult(False,
|
||||
|
|
Loading…
Reference in a new issue