Stop requiring super call to activate event handlers in plugin start/stop methods
This commit is contained in:
parent
7e6c51d18f
commit
8b0bd510f9
@ -173,7 +173,7 @@ class PluginInstance:
|
||||
database=self.inst_db, webapp=self.inst_webapp,
|
||||
webapp_url=self.inst_webapp_url)
|
||||
try:
|
||||
await self.plugin.start()
|
||||
await self.plugin.internal_start()
|
||||
except Exception:
|
||||
self.log.exception("Failed to start instance")
|
||||
self.db_instance.enabled = False
|
||||
@ -190,7 +190,7 @@ class PluginInstance:
|
||||
self.log.debug("Stopping plugin instance...")
|
||||
self.started = False
|
||||
try:
|
||||
await self.plugin.stop()
|
||||
await self.plugin.internal_stop()
|
||||
except Exception:
|
||||
self.log.exception("Failed to stop instance")
|
||||
self.plugin = None
|
||||
|
@ -52,7 +52,7 @@ class Plugin(ABC):
|
||||
self.webapp_url = webapp_url
|
||||
self._handlers_at_startup = []
|
||||
|
||||
async def start(self) -> None:
|
||||
async def internal_start(self) -> None:
|
||||
for key in dir(self):
|
||||
val = getattr(self, key)
|
||||
try:
|
||||
@ -67,12 +67,20 @@ class Plugin(ABC):
|
||||
self.webapp.add_route(method=method, path=path, handler=val, **kwargs)
|
||||
except AttributeError:
|
||||
pass
|
||||
await self.start()
|
||||
|
||||
async def stop(self) -> None:
|
||||
async def start(self) -> None:
|
||||
pass
|
||||
|
||||
async def internal_stop(self) -> None:
|
||||
for func, event_type in self._handlers_at_startup:
|
||||
self.client.remove_event_handler(event_type, func)
|
||||
if self.webapp is not None:
|
||||
self.webapp.clear()
|
||||
await self.stop()
|
||||
|
||||
async def stop(self) -> None:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def get_config_class(cls) -> Optional[Type['BaseProxyConfig']]:
|
||||
|
Loading…
Reference in New Issue
Block a user