Skip to content

Commit

Permalink
allow start staged app
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Sep 27, 2024
1 parent e98b6b6 commit 20279a3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions hypha/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,12 @@ async def commit(
"""Finalize the edits to the application by committing the artifact."""

prefix = f"applications/{app_id}"
await self.artifact_controller.commit(prefix=prefix, context=context)
try:
info = await self.start(
app_id,
timeout=timeout,
wait_for_service="default",
stage=True,
context=context,
)
await self.stop(info["id"], context=context)
Expand All @@ -311,6 +311,7 @@ async def commit(
raise Exception(
f"Failed to start the app: {app_id} during installation, error: {exp}"
)
await self.artifact_controller.commit(prefix=prefix, context=context)

async def uninstall(self, app_id: str, context: Optional[dict] = None) -> None:
"""Uninstall an application by removing its artifact."""
Expand Down Expand Up @@ -346,6 +347,7 @@ async def start(
app_id,
client_id=None,
timeout: float = 60,
stage: bool = False,
wait_for_service: Union[str, bool] = None,
context: Optional[dict] = None,
):
Expand All @@ -371,7 +373,7 @@ async def start(
client_id = random_id(readable=True)

artifact = await self.artifact_controller.read(
prefix=f"applications/{app_id}", context=context
prefix=f"applications/{app_id}", stage=stage, context=context
)
artifact = ApplicationArtifact.model_validate(artifact)

Expand Down Expand Up @@ -447,13 +449,16 @@ def service_added(info: dict):
artifact = ApplicationArtifact.model_validate(
artifact.model_dump(mode="json")
)
await self.artifact_controller.create(
await self.artifact_controller.edit(
prefix=f"applications/{app_id}",
manifest=artifact.model_dump(mode="json"),
overwrite=True,
stage=False,
context=context,
)
if not stage:
await self.artifact_controller.commit(
prefix=f"applications/{app_id}", context=context
)

except asyncio.TimeoutError:
raise Exception(
f"Failed to start the app: {workspace}/{app_id}, timeout reached ({timeout}s)."
Expand Down

0 comments on commit 20279a3

Please sign in to comment.