-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support managed jobs dashboard (#46)
* [perf] use uv for venv creation and pip install (#4414) * Revert "remove `uv` from runtime setup due to azure installation issue (#4401)" This reverts commit 0b20d56. * on azure, use --prerelease=allow to install azure-cli * use uv venv --seed * fix backwards compatibility * really fix backwards compatibility * use uv to set up controller dependencies * fix python 3.8 * lint * add missing file * update comment * split out azure-cli dep * fix lint for dependencies * use runpy.run_path rather than modifying sys.path * fix cloud dependency installation commands * lint * Update sky/utils/controller_utils.py Co-authored-by: Zhanghao Wu <[email protected]> --------- Co-authored-by: Zhanghao Wu <[email protected]> * [Minor] README updates. (#4436) * [Minor] README touches. * update * update * basic impl * fixes * start dashboard when restarting the controller * Fix dashboard support * Fix * format * format * format * format * format * address comments * format * fix --------- Co-authored-by: Christopher Cooper <[email protected]> Co-authored-by: Zongheng Yang <[email protected]>
- Loading branch information
1 parent
7b24232
commit b46a994
Showing
9 changed files
with
274 additions
and
73 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
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,64 @@ | ||
"""Persistent dashboard sessions.""" | ||
import pathlib | ||
from typing import Tuple | ||
|
||
import filelock | ||
|
||
from sky.utils import db_utils | ||
|
||
|
||
def create_dashboard_table(cursor, conn): | ||
cursor.execute("""\ | ||
CREATE TABLE IF NOT EXISTS dashboard_sessions ( | ||
user_hash TEXT PRIMARY KEY, | ||
port INTEGER, | ||
pid INTEGER)""") | ||
conn.commit() | ||
|
||
|
||
def _get_db_path() -> str: | ||
path = pathlib.Path('~/.sky/dashboard/sessions.db') | ||
path = path.expanduser().absolute() | ||
path.parent.mkdir(parents=True, exist_ok=True) | ||
return str(path) | ||
|
||
|
||
DB_PATH = _get_db_path() | ||
db_utils.SQLiteConn(DB_PATH, create_dashboard_table) | ||
LOCK_FILE_PATH = '~/.sky/dashboard/sessions-{user_hash}.lock' | ||
|
||
|
||
def get_dashboard_session(user_hash: str) -> Tuple[int, int]: | ||
"""Get the port and pid of the dashboard session for the user.""" | ||
with db_utils.safe_cursor(DB_PATH) as cursor: | ||
cursor.execute( | ||
'SELECT port, pid FROM dashboard_sessions WHERE user_hash=?', | ||
(user_hash,)) | ||
result = cursor.fetchone() | ||
if result is None: | ||
return 0, 0 | ||
return result | ||
|
||
|
||
def add_dashboard_session(user_hash: str, port: int, pid: int) -> None: | ||
"""Add a dashboard session for the user.""" | ||
with db_utils.safe_cursor(DB_PATH) as cursor: | ||
cursor.execute( | ||
'INSERT OR REPLACE INTO dashboard_sessions (user_hash, port, pid) ' | ||
'VALUES (?, ?, ?)', (user_hash, port, pid)) | ||
|
||
|
||
def remove_dashboard_session(user_hash: str) -> None: | ||
"""Remove the dashboard session for the user.""" | ||
with db_utils.safe_cursor(DB_PATH) as cursor: | ||
cursor.execute('DELETE FROM dashboard_sessions WHERE user_hash=?', | ||
(user_hash,)) | ||
lock_path = pathlib.Path(LOCK_FILE_PATH.format(user_hash=user_hash)) | ||
lock_path.unlink(missing_ok=True) | ||
|
||
|
||
def get_dashboard_lock_for_user(user_hash: str) -> filelock.FileLock: | ||
path = pathlib.Path(LOCK_FILE_PATH.format(user_hash=user_hash)) | ||
path = path.expanduser().absolute() | ||
path.parent.mkdir(parents=True, exist_ok=True) | ||
return filelock.FileLock(path) |
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
Oops, something went wrong.