-
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.
- Loading branch information
1 parent
0943f0a
commit 86b3c0a
Showing
2 changed files
with
25 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,30 @@ | ||
import time | ||
import logging | ||
import subprocess | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class AutostopServlet: | ||
"""A helper class strictly to run SkyPilot methods on OnDemandClusters inside SkyPilot's conda env.""" | ||
|
||
def __init__(self): | ||
self._last_activity = time.time() | ||
self._last_register = None | ||
self._activity_registered = False | ||
|
||
def set_last_active_time_to_now(self): | ||
self._last_activity = time.time() | ||
|
||
def set_autostop(self, value=None): | ||
from sky.skylet import autostop_lib | ||
|
||
self.set_last_active_time_to_now() | ||
autostop_lib.set_autostop(value, None, True) | ||
self._activity_registered = True | ||
|
||
def update_autostop_in_sky_config(self): | ||
from sky.skylet.autostop_lib import set_last_active_time_to_now | ||
|
||
if self._last_register is None or self._last_register < self._last_activity: | ||
set_last_active_time_to_now() | ||
self._last_register = self._last_activity | ||
SKY_VENV = "~/skypilot-runtime" | ||
SKY_AUTOSTOP_CMD = "from sky.skylet.autostop_lib import set_last_active_time_to_now; set_last_active_time_to_now()" | ||
SKY_CMD = f"{SKY_VENV}/bin/python -c '{SKY_AUTOSTOP_CMD}'" | ||
|
||
if self._activity_registered: | ||
logger.debug( | ||
"Activity registered, updating last active time in SkyConfig with command: {SKY_CMD}" | ||
) | ||
subprocess.run(SKY_CMD, shell=True, check=True) | ||
self._activity_registered = False | ||
else: | ||
logger.debug( | ||
"No activity registered, not updating last active time in SkyConfig" | ||
) |
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