Try reloading failed instance dependencies when starting instance
This commit is contained in:
parent
07fe46e7f9
commit
1552964d3f
@ -73,21 +73,24 @@ class PluginInstance:
|
||||
"config": self.db_instance.config,
|
||||
}
|
||||
|
||||
def load(self) -> None:
|
||||
def load(self) -> bool:
|
||||
if not self.loader:
|
||||
try:
|
||||
self.loader = PluginLoader.find(self.type)
|
||||
except KeyError:
|
||||
self.log.error(f"Failed to find loader for type {self.type}")
|
||||
self.db_instance.enabled = False
|
||||
return
|
||||
return False
|
||||
if not self.client:
|
||||
self.client = Client.get(self.primary_user)
|
||||
if not self.client:
|
||||
self.log.error(f"Failed to get client for user {self.primary_user}")
|
||||
self.db_instance.enabled = False
|
||||
return
|
||||
return False
|
||||
self.log.debug("Plugin instance dependencies loaded")
|
||||
self.loader.references.add(self)
|
||||
self.client.references.add(self)
|
||||
return True
|
||||
|
||||
def delete(self) -> None:
|
||||
if self.loader is not None:
|
||||
@ -117,6 +120,10 @@ class PluginInstance:
|
||||
elif not self.enabled:
|
||||
self.log.warning("Plugin disabled, not starting.")
|
||||
return
|
||||
if not self.client or not self.loader:
|
||||
self.log.warning("Missing plugin instance dependencies, attempting to load...")
|
||||
if not self.load():
|
||||
return
|
||||
cls = await self.loader.load()
|
||||
config_class = cls.get_config_class()
|
||||
if config_class:
|
||||
@ -184,6 +191,7 @@ class PluginInstance:
|
||||
return False
|
||||
await self.stop()
|
||||
self.db_instance.primary_user = client.id
|
||||
if self.client:
|
||||
self.client.references.remove(self)
|
||||
self.client = client
|
||||
self.client.references.add(self)
|
||||
@ -200,6 +208,7 @@ class PluginInstance:
|
||||
return False
|
||||
await self.stop()
|
||||
self.db_instance.type = loader.meta.id
|
||||
if self.loader:
|
||||
self.loader.references.remove(self)
|
||||
self.loader = loader
|
||||
self.loader.references.add(self)
|
||||
|
Loading…
Reference in New Issue
Block a user