Skip to content

Commit 22eeb5b

Browse files
kiukchungfacebook-github-bot
authored andcommitted
(monarch/tools) Add force_restart argument to get_or_create command
Summary: `force_restart=True` will kill the existing job and force it to create again. Useful when we want to redeploy the server to reflect any changes in the local conda/workspace that are not eligible for CodeSync. NOTE: this is tangential to setting `workspace=None` which disables local conda AND workspace building into an ephemeral image. Reviewed By: ahmadsharif1 Differential Revision: D79754696
1 parent 3bb4ea9 commit 22eeb5b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

python/monarch/tools/commands.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ async def get_or_create(
265265
name: str,
266266
config: Config,
267267
check_interval: timedelta = _5_SECONDS,
268+
force_restart: bool = False,
268269
) -> ServerSpec:
269270
"""Waits for the server based on identity `name` in the scheduler specified in the `config`
270271
to be ready (e.g. RUNNING). If the server is not found then this function creates one
@@ -286,6 +287,7 @@ async def get_or_create(
286287
name: the name of the server (job) to get or create
287288
config: configs used to create the job if one does not exist
288289
check_interval: how often to poll the status of the job when waiting for it to be ready
290+
force_restart: if True kills and re-creates the job even if one exists
289291
290292
Returns: A `ServerSpec` containing information about either the existing or the newly
291293
created server.
@@ -322,6 +324,12 @@ async def get_or_create(
322324
return server_info
323325
else:
324326
print(f"{CYAN}Found existing job `{server_handle}` ready to serve.{ENDC}")
327+
328+
if force_restart:
329+
print(f"{CYAN}force_restart=True, restarting `{server_handle}`{ENDC}")
330+
kill(server_handle)
331+
server_info = await get_or_create(name, config, check_interval)
332+
325333
return server_info
326334

327335

0 commit comments

Comments
 (0)