-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
5 changed files
with
48 additions
and
18 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
from dotenv import load_dotenv | ||
from src.utils.subprocess_operations import ( | ||
get_piped_stdout, | ||
stdout_to_records, | ||
job_records_to_slack_message, | ||
) | ||
from src.hooks.slack import send_slack_message | ||
|
||
load_dotenv() | ||
SLACK_WEBHOOK = os.getenv("SLACK_GPU_JOBS_WEBHOOK") | ||
PARTITIONS: list[str] = os.getenv("PARTITIONS").split(",") | ||
HEADER = ["PARTITION", "AVAILABILITY", "TIMELIMIT", "NODES", "STATE", "NODELIST"] | ||
|
||
|
||
def get_idle_nodes() -> str: | ||
main_cmd = "sinfo -t idle" | ||
piped_cmd = "grep gpu" | ||
return get_piped_stdout(main_cmd, piped_cmd) | ||
|
||
|
||
def monitor(): | ||
idle_nodes = get_idle_nodes() | ||
idle_node_records = stdout_to_records(HEADER, idle_nodes) | ||
header = "🟢Available nodes in Bunya\n\n" | ||
filtered_idle_node_records = list(filter(lambda x: x["PARTITION"] in PARTITIONS, idle_node_records)) | ||
slack_message = job_records_to_slack_message(header, filtered_idle_node_records) | ||
send_slack_message(slack_message, SLACK_WEBHOOK) | ||
|
||
|
||
if __name__ == "__main__": | ||
monitor() |
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import json | ||
from .subprocess_operations import JOB_RECORDS | ||
from .subprocess_operations import RECORDS | ||
|
||
|
||
def write_job_records_to_json(records: JOB_RECORDS, filepath: str): | ||
def write_job_records_to_json(records: RECORDS, filepath: str): | ||
json_data = json.dumps(records, indent=2) | ||
with open(filepath, "w") as outfile: | ||
outfile.write(json_data) | ||
|
||
|
||
def read_json_as_job_records(filepath: str) -> JOB_RECORDS: | ||
def read_json_as_job_records(filepath: str) -> RECORDS: | ||
f = open(filepath, "r") | ||
return json.loads(f.read()) |
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