-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change AutostopServlet into AutostopHelper, and test properly (#897)
AutostopServlet is no longer in its own process because it's easier to just run python commands in SkyPilot's venv through subprocess than start an actor inside that interpreter. Here we're changing the AutostopServlet to AutostopHelper (a regular class, not an Actor), fleshing out the available autostop commands it can make, and testing it thoroughly. Previously keep_warm or the cluster.autostop_mins setter wouldn't work if called on the cluster, now they do.
- Loading branch information
1 parent
9a61f2c
commit c4c65cc
Showing
5 changed files
with
188 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import logging | ||
import shlex | ||
import subprocess | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class AutostopHelper: | ||
"""A helper class strictly to run SkyPilot methods on OnDemandClusters inside SkyPilot's conda env.""" | ||
|
||
SKY_VENV = "~/skypilot-runtime" | ||
|
||
def __init__(self): | ||
self._activity_registered = False | ||
|
||
async def set_last_active_time_to_now(self): | ||
self._activity_registered = True | ||
|
||
def _run_python_in_sky_venv(self, cmd: str): | ||
sky_python_cmd = f"{self.SKY_VENV}/bin/python -c {cmd}" | ||
|
||
logger.debug(f"Running command in SkyPilot's venv: {sky_python_cmd}") | ||
# run with subprocess and return the output | ||
return subprocess.run( | ||
sky_python_cmd, | ||
shell=True, | ||
check=True, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
).stdout.decode("utf-8") | ||
|
||
async def get_autostop(self): | ||
sky_get_autostop_cmd = shlex.quote( | ||
"from sky.skylet.autostop_lib import get_autostop_config; " | ||
"print(get_autostop_config().autostop_idle_minutes)" | ||
) | ||
|
||
return int(self._run_python_in_sky_venv(sky_get_autostop_cmd)) | ||
|
||
async def get_last_active_time(self): | ||
sky_get_last_active_time_cmd = shlex.quote( | ||
"from sky.skylet.autostop_lib import get_last_active_time; " | ||
"print(get_last_active_time())" | ||
) | ||
|
||
return float(self._run_python_in_sky_venv(sky_get_last_active_time_cmd)) | ||
|
||
async def set_autostop(self, idle_minutes: int): | ||
# Filling in "cloudvmray" as the backend because it's the only backend supported by SkyPilot right now, | ||
# if needed we can grab the backend from the autostop config with: | ||
# `from sky.skylet.autostop_lib import get_autostop_config; get_autostop_config().backend` | ||
sky_set_autostop_cmd = shlex.quote( | ||
f"from sky.skylet.autostop_lib import set_autostop; " | ||
f'set_autostop({idle_minutes}, "cloudvmray", True)' | ||
) | ||
|
||
self._run_python_in_sky_venv(sky_set_autostop_cmd) | ||
|
||
async def register_activity_if_needed(self): | ||
sky_register_activity_cmd = shlex.quote( | ||
"from sky.skylet.autostop_lib import set_last_active_time_to_now; " | ||
"set_last_active_time_to_now()" | ||
) | ||
|
||
if self._activity_registered: | ||
logger.debug("Activity registered, updating last active time in SkyConfig") | ||
self._run_python_in_sky_venv(sky_register_activity_cmd) | ||
self._activity_registered = False | ||
else: | ||
logger.debug( | ||
"No activity registered, not updating last active time in SkyConfig" | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters