feat: switch async

This commit is contained in:
Yeuoly 2026-01-22 19:42:09 +08:00
parent c3b4029d0b
commit 3058415b4e
2 changed files with 17 additions and 0 deletions

View File

@ -113,10 +113,21 @@ class SandboxBuilder:
assets_id=self._assets_id, assets_id=self._assets_id,
) )
"""
# Run synchronous initializers before marking sandbox as ready.
"""
for init in self._initializers:
if init.async_initialize():
continue
init.initialize(sandbox)
# Run sandbox setup asynchronously so workflow execution can proceed. # Run sandbox setup asynchronously so workflow execution can proceed.
def initialize() -> None: def initialize() -> None:
try: try:
for init in self._initializers: for init in self._initializers:
if not init.async_initialize():
continue
if sandbox.is_cancelled(): if sandbox.is_cancelled():
return return
init.initialize(sandbox) init.initialize(sandbox)

View File

@ -6,3 +6,9 @@ from core.sandbox.sandbox import Sandbox
class SandboxInitializer(ABC): class SandboxInitializer(ABC):
@abstractmethod @abstractmethod
def initialize(self, env: Sandbox) -> None: ... def initialize(self, env: Sandbox) -> None: ...
def async_initialize(self) -> bool:
"""
Whether the initializer needs to run asynchronously.
"""
return False