mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 17:08:03 +08:00
feat: add async_initialize method to asset initializers
This commit is contained in:
16
api/core/sandbox/initializer/app_assets_attrs_loader.py
Normal file
16
api/core/sandbox/initializer/app_assets_attrs_loader.py
Normal file
@ -0,0 +1,16 @@
|
||||
from core.app_assets.constants import AppAssetsAttrs
|
||||
from core.sandbox.initializer.base import SandboxInitializer
|
||||
from core.sandbox.sandbox import Sandbox
|
||||
from services.app_asset_service import AppAssetService
|
||||
|
||||
|
||||
class AppAssetsAttrsInitializer(SandboxInitializer):
|
||||
def __init__(self, tenant_id: str, app_id: str, assets_id: str) -> None:
|
||||
self._tenant_id = tenant_id
|
||||
self._app_id = app_id
|
||||
self._assets_id = assets_id
|
||||
|
||||
def initialize(self, env: Sandbox) -> None:
|
||||
# Load published app assets and unzip the artifact bundle.
|
||||
app_assets = AppAssetService.get_tenant_app_assets(self._tenant_id, self._assets_id)
|
||||
env.attrs.set(AppAssetsAttrs.FILE_TREE, app_assets.asset_tree)
|
||||
@ -1,12 +1,10 @@
|
||||
import logging
|
||||
|
||||
from core.app_assets.constants import AppAssetsAttrs
|
||||
from core.app_assets.paths import AssetPaths
|
||||
from core.sandbox.sandbox import Sandbox
|
||||
from core.virtual_environment.__base.helpers import pipeline
|
||||
from extensions.ext_storage import storage
|
||||
from extensions.storage.file_presign_storage import FilePresignStorage
|
||||
from services.app_asset_service import AppAssetService
|
||||
|
||||
from ..entities import AppAssets
|
||||
from .base import SandboxInitializer
|
||||
@ -24,10 +22,6 @@ class AppAssetsInitializer(SandboxInitializer):
|
||||
|
||||
def initialize(self, env: Sandbox) -> None:
|
||||
vm = env.vm
|
||||
# Load published app assets and unzip the artifact bundle.
|
||||
app_assets = AppAssetService.get_tenant_app_assets(self._tenant_id, self._assets_id)
|
||||
env.attrs.set(AppAssetsAttrs.FILE_TREE, app_assets.asset_tree)
|
||||
|
||||
zip_key = AssetPaths.build_zip(self._tenant_id, self._app_id, self._assets_id)
|
||||
download_url = FilePresignStorage(storage.storage_runner).get_download_url(zip_key)
|
||||
|
||||
@ -51,3 +45,6 @@ class AppAssetsInitializer(SandboxInitializer):
|
||||
self._app_id,
|
||||
self._assets_id,
|
||||
)
|
||||
|
||||
def async_initialize(self) -> bool:
|
||||
return True
|
||||
|
||||
@ -82,3 +82,6 @@ class DifyCliInitializer(SandboxInitializer):
|
||||
).execute(raise_on_error=True)
|
||||
|
||||
logger.info("Global tools initialized, path=%s, tool_count=%d", DifyCli.GLOBAL_TOOLS_PATH, len(self._tools))
|
||||
|
||||
def async_initialize(self) -> bool:
|
||||
return True
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import logging
|
||||
|
||||
from core.app_assets.constants import AppAssetsAttrs
|
||||
from core.sandbox.entities import AppAssets
|
||||
from core.sandbox.sandbox import Sandbox
|
||||
from core.sandbox.services import AssetDownloadService
|
||||
@ -24,8 +23,8 @@ class DraftAppAssetsInitializer(SandboxInitializer):
|
||||
def initialize(self, env: Sandbox) -> None:
|
||||
vm = env.vm
|
||||
# Draft assets download via presigned URLs to avoid zip build overhead.
|
||||
# FIXME(Yeuoly): merge 2 IO operations in DraftAppAssetsInitializer and AppAssetsAttrsInitializer
|
||||
app_assets = AppAssetService.get_tenant_app_assets(self._tenant_id, self._assets_id)
|
||||
env.attrs.set(AppAssetsAttrs.FILE_TREE, app_assets.asset_tree)
|
||||
|
||||
items = [
|
||||
AssetDownloadItem(path=path, url=url)
|
||||
@ -42,3 +41,6 @@ class DraftAppAssetsInitializer(SandboxInitializer):
|
||||
self._app_id,
|
||||
self._assets_id,
|
||||
)
|
||||
|
||||
def async_initialize(self) -> bool:
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user