Skip to content

Commit d5b83c0

Browse files
committed
cleanup
1 parent 5c63629 commit d5b83c0

1 file changed

Lines changed: 12 additions & 30 deletions

File tree

examples/devbox_snapshots.py

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
from runloop_api_client import AsyncRunloopSDK
3535
from runloop_api_client.lib.polling import PollingConfig
36-
from runloop_api_client.sdk.async_devbox import AsyncDevbox
3736

3837
from ._harness import run_as_cli, unique_name, wrap_recipe
3938
from .example_types import ExampleCheck, RecipeOutput, RecipeContext
@@ -42,11 +41,6 @@
4241
POLLING_CONFIG = PollingConfig(timeout_seconds=120.0, interval_seconds=5.0)
4342

4443

45-
async def read_file_contents(devbox: AsyncDevbox) -> str:
46-
"""Read the shared demo file from a devbox."""
47-
return await devbox.file.read(file_path=FILE_PATH)
48-
49-
5044
async def recipe(ctx: RecipeContext) -> RecipeOutput:
5145
"""Demonstrate suspend/resume and shared snapshot restoration with isolated mutations."""
5246
cleanup = ctx.cleanup
@@ -69,22 +63,22 @@ async def recipe(ctx: RecipeContext) -> RecipeOutput:
6963
name=unique_name("snapshot-source"),
7064
launch_parameters={
7165
"resource_size_request": "X_SMALL",
66+
"keep_alive_time_seconds": 60 * 5,
7267
},
7368
)
7469
cleanup.add(f"devbox:{source_devbox.id}", source_devbox.shutdown)
7570
resources_created.append(f"devbox:{source_devbox.id}")
7671

7772
await source_devbox.file.upload(path=FILE_PATH, file=local_file_path)
78-
uploaded_readback = await read_file_contents(source_devbox)
73+
uploaded_readback = await source_devbox.file.read(file_path=FILE_PATH)
7974

8075
await source_devbox.file.write(file_path=FILE_PATH, contents=baseline_contents)
8176

82-
suspended_info = await source_devbox.suspend()
83-
if suspended_info.status != "suspended":
84-
suspended_info = await source_devbox.await_suspended(polling_config=POLLING_CONFIG)
77+
await source_devbox.suspend()
78+
suspended_info = await source_devbox.await_suspended(polling_config=POLLING_CONFIG)
8579

8680
resumed_info = await source_devbox.resume(polling_config=POLLING_CONFIG)
87-
resumed_readback = await read_file_contents(source_devbox)
81+
resumed_readback = await source_devbox.file.read(file_path=FILE_PATH)
8882

8983
snapshot = await source_devbox.snapshot_disk(
9084
name=unique_name("snapshot-baseline"),
@@ -98,6 +92,7 @@ async def recipe(ctx: RecipeContext) -> RecipeOutput:
9892
name=unique_name("snapshot-clone-a"),
9993
launch_parameters={
10094
"resource_size_request": "X_SMALL",
95+
"keep_alive_time_seconds": 60 * 5,
10196
},
10297
)
10398
cleanup.add(f"devbox:{clone_a.id}", clone_a.shutdown)
@@ -110,21 +105,22 @@ async def recipe(ctx: RecipeContext) -> RecipeOutput:
110105
name=unique_name("snapshot-clone-b"),
111106
launch_parameters={
112107
"resource_size_request": "X_SMALL",
108+
"keep_alive_time_seconds": 60 * 5,
113109
},
114110
)
115111
cleanup.add(f"devbox:{clone_b.id}", clone_b.shutdown)
116112
resources_created.append(f"devbox:{clone_b.id}")
117113

118-
clone_a_baseline_readback = await read_file_contents(clone_a)
119-
clone_b_baseline_readback = await read_file_contents(clone_b)
114+
clone_a_baseline_readback = await clone_a.file.read(file_path=FILE_PATH)
115+
clone_b_baseline_readback = await clone_b.file.read(file_path=FILE_PATH)
120116

121117
await source_devbox.file.write(file_path=FILE_PATH, contents=source_contents)
122118
await clone_a.file.write(file_path=FILE_PATH, contents=clone_a_contents)
123119
await clone_b.file.write(file_path=FILE_PATH, contents=clone_b_contents)
124120

125-
source_isolated_readback = await read_file_contents(source_devbox)
126-
clone_a_isolated_readback = await read_file_contents(clone_a)
127-
clone_b_isolated_readback = await read_file_contents(clone_b)
121+
source_isolated_readback = await source_devbox.file.read(file_path=FILE_PATH)
122+
clone_a_isolated_readback = await clone_a.file.read(file_path=FILE_PATH)
123+
clone_b_isolated_readback = await clone_b.file.read(file_path=FILE_PATH)
128124

129125
return RecipeOutput(
130126
resources_created=resources_created,
@@ -165,20 +161,6 @@ async def recipe(ctx: RecipeContext) -> RecipeOutput:
165161
f"clone_b={clone_b_isolated_readback}"
166162
),
167163
),
168-
ExampleCheck(
169-
name="snapshot-backed devboxes stay isolated from one another",
170-
passed=(
171-
len(
172-
{
173-
source_isolated_readback,
174-
clone_a_isolated_readback,
175-
clone_b_isolated_readback,
176-
}
177-
)
178-
== 3
179-
),
180-
details=(f"values={[source_isolated_readback, clone_a_isolated_readback, clone_b_isolated_readback]}"),
181-
),
182164
],
183165
)
184166

0 commit comments

Comments
 (0)