-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58427a5
commit 64f8549
Showing
6 changed files
with
132 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import asyncio | ||
from typing import TYPE_CHECKING | ||
|
||
from launart import Launart, Service | ||
from launart.status import Phase | ||
from loguru import logger | ||
|
||
if TYPE_CHECKING: | ||
from .model import Plugin | ||
|
||
|
||
class PluginService(Service): | ||
id = "arclet.entari.plugin_service" | ||
|
||
plugins: dict[str, "Plugin"] | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.plugins = {} | ||
|
||
@property | ||
def required(self) -> set[str]: | ||
return set() | ||
|
||
@property | ||
def stages(self) -> set[Phase]: | ||
return {"preparing", "cleanup"} | ||
|
||
async def launch(self, manager: Launart): | ||
_preparing = [] | ||
_cleanup = [] | ||
for plug in self.plugins.values(): | ||
_preparing.extend([func() for func in plug._preparing]) | ||
_cleanup.extend([func() for func in plug._cleanup]) | ||
async with self.stage("preparing"): | ||
await asyncio.gather(*_preparing, return_exceptions=True) | ||
async with self.stage("cleanup"): | ||
await asyncio.gather(*_cleanup, return_exceptions=True) | ||
ids = [*self.plugins.keys()] | ||
for plug_id in ids: | ||
plug = self.plugins[plug_id] | ||
logger.debug(f"disposing plugin {plug.id}") | ||
try: | ||
plug.dispose() | ||
except Exception as e: | ||
logger.error(f"failed to dispose plugin {plug.id} caused by {e!r}") | ||
self.plugins.pop(plug_id, None) | ||
|
||
|
||
service = PluginService() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters