moonraker: call optional "on_exit()" plugin method before "close()"
This allows plugins to interact with other plugins before they are closed. For example, a plugin may wish to save persistent state to the database before it is closed. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
5144508410
commit
2e0d3f36b4
|
@ -480,14 +480,18 @@ class Server:
|
|||
|
||||
async def _stop_server(self, exit_reason="restart"):
|
||||
self.server_running = False
|
||||
for method in ["on_exit", "close"]:
|
||||
for name, plugin in self.plugins.items():
|
||||
if hasattr(plugin, "close"):
|
||||
if not hasattr(plugin, method):
|
||||
continue
|
||||
func = getattr(plugin, method)
|
||||
try:
|
||||
ret = plugin.close()
|
||||
ret = func()
|
||||
if asyncio.iscoroutine(ret):
|
||||
await ret
|
||||
except Exception:
|
||||
logging.exception(f"Error closing plugin: {name}")
|
||||
logging.exception(
|
||||
f"Error executing '{method}()' for plugin: {name}")
|
||||
try:
|
||||
if self.klippy_connection.is_connected():
|
||||
self.klippy_disconnect_evt = Event()
|
||||
|
|
Loading…
Reference in New Issue