mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 03:29:01 +08:00
fix: ignore plugin already exists (#13888)
This commit is contained in:
parent
363c46ace8
commit
4dae0e514e
@ -707,12 +707,13 @@ def extract_unique_plugins(output_file: str, input_file: str):
|
|||||||
@click.option(
|
@click.option(
|
||||||
"--output_file", prompt=True, help="The file to store the installed plugins.", default="installed_plugins.jsonl"
|
"--output_file", prompt=True, help="The file to store the installed plugins.", default="installed_plugins.jsonl"
|
||||||
)
|
)
|
||||||
def install_plugins(input_file: str, output_file: str):
|
@click.option("--workers", prompt=True, help="The number of workers to install plugins.", default=100)
|
||||||
|
def install_plugins(input_file: str, output_file: str, workers: int):
|
||||||
"""
|
"""
|
||||||
Install plugins.
|
Install plugins.
|
||||||
"""
|
"""
|
||||||
click.echo(click.style("Starting install plugins.", fg="white"))
|
click.echo(click.style("Starting install plugins.", fg="white"))
|
||||||
|
|
||||||
PluginMigration.install_plugins(input_file, output_file)
|
PluginMigration.install_plugins(input_file, output_file, workers)
|
||||||
|
|
||||||
click.echo(click.style("Install plugins completed.", fg="green"))
|
click.echo(click.style("Install plugins completed.", fg="green"))
|
||||||
|
@ -356,7 +356,7 @@ class PluginMigration:
|
|||||||
return {"plugins": plugins, "plugin_not_exist": plugin_not_exist}
|
return {"plugins": plugins, "plugin_not_exist": plugin_not_exist}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def install_plugins(cls, extracted_plugins: str, output_file: str) -> None:
|
def install_plugins(cls, extracted_plugins: str, output_file: str, workers: int = 100) -> None:
|
||||||
"""
|
"""
|
||||||
Install plugins.
|
Install plugins.
|
||||||
"""
|
"""
|
||||||
@ -370,7 +370,7 @@ class PluginMigration:
|
|||||||
fake_tenant_id = uuid4().hex
|
fake_tenant_id = uuid4().hex
|
||||||
logger.info(f"Installing {len(plugins['plugins'])} plugin instances for fake tenant {fake_tenant_id}")
|
logger.info(f"Installing {len(plugins['plugins'])} plugin instances for fake tenant {fake_tenant_id}")
|
||||||
|
|
||||||
thread_pool = ThreadPoolExecutor(max_workers=40)
|
thread_pool = ThreadPoolExecutor(max_workers=workers)
|
||||||
|
|
||||||
response = cls.handle_plugin_instance_install(fake_tenant_id, plugins["plugins"])
|
response = cls.handle_plugin_instance_install(fake_tenant_id, plugins["plugins"])
|
||||||
if response.get("failed"):
|
if response.get("failed"):
|
||||||
@ -378,10 +378,17 @@ class PluginMigration:
|
|||||||
|
|
||||||
def install(tenant_id: str, plugin_ids: list[str]) -> None:
|
def install(tenant_id: str, plugin_ids: list[str]) -> None:
|
||||||
logger.info(f"Installing {len(plugin_ids)} plugins for tenant {tenant_id}")
|
logger.info(f"Installing {len(plugin_ids)} plugins for tenant {tenant_id}")
|
||||||
|
# fetch plugin already installed
|
||||||
|
installed_plugins = manager.list_plugins(tenant_id)
|
||||||
|
installed_plugins_ids = [plugin.plugin_id for plugin in installed_plugins]
|
||||||
# at most 64 plugins one batch
|
# at most 64 plugins one batch
|
||||||
for i in range(0, len(plugin_ids), 64):
|
for i in range(0, len(plugin_ids), 64):
|
||||||
batch_plugin_ids = plugin_ids[i : i + 64]
|
batch_plugin_ids = plugin_ids[i : i + 64]
|
||||||
batch_plugin_identifiers = [plugins["plugins"][plugin_id] for plugin_id in batch_plugin_ids]
|
batch_plugin_identifiers = [
|
||||||
|
plugins["plugins"][plugin_id]
|
||||||
|
for plugin_id in batch_plugin_ids
|
||||||
|
if plugin_id not in installed_plugins_ids
|
||||||
|
]
|
||||||
manager.install_from_identifiers(
|
manager.install_from_identifiers(
|
||||||
tenant_id,
|
tenant_id,
|
||||||
batch_plugin_identifiers,
|
batch_plugin_identifiers,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user