Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libs/sdk-python/src/daytona/_async/daytona.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,16 @@ async def should_terminate():
SandboxState.BUILD_FAILED,
]

pending_build_start = time.time()

while response_ref["response"].state == SandboxState.PENDING_BUILD:
if timeout:
elapsed = time.time() - pending_build_start
if elapsed > timeout:
raise DaytonaError(
f"Sandbox build has been pending for more than {timeout} seconds."
f"Please check the sandbox state again later."
)
await asyncio.sleep(1)
response_ref["response"] = await self._sandbox_api.get_sandbox(response_ref["response"].id)

Expand Down
9 changes: 9 additions & 0 deletions libs/sdk-python/src/daytona/_sync/daytona.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,16 @@ def should_terminate():
SandboxState.BUILD_FAILED,
]

pending_build_start = time.time()

while response_ref["response"].state == SandboxState.PENDING_BUILD:
if timeout:
elapsed = time.time() - pending_build_start
if elapsed > timeout:
raise DaytonaError(
f"Sandbox build has been pending for more than {timeout} seconds."
f"Please check the sandbox state again later."
)
time.sleep(1)
response_ref["response"] = self._sandbox_api.get_sandbox(response_ref["response"].id)

Expand Down
10 changes: 10 additions & 0 deletions libs/sdk-typescript/src/Daytona.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,17 @@ export class Daytona {
SandboxState.BUILD_FAILED,
]

const pendingBuildStart = Date.now()

while (sandboxInstance.state === SandboxState.PENDING_BUILD) {
if (options.timeout) {
const elapsed = (Date.now() - pendingBuildStart) / 1000
if (elapsed > options.timeout) {
throw new DaytonaError(
`Sandbox build has been pending for more than ${options.timeout} seconds. Please check the sandbox state again later.`,
)
}
}
await new Promise((resolve) => setTimeout(resolve, 1000))
sandboxInstance = (await this.sandboxApi.getSandbox(sandboxInstance.id)).data
}
Expand Down
Loading