Skip to content

Commit

Permalink
quota limit check ready to be tested
Browse files Browse the repository at this point in the history
  • Loading branch information
kerrychu committed Jan 23, 2024
1 parent ed7ef51 commit 6c51ca0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
11 changes: 7 additions & 4 deletions quota_limit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from dotenv import load_dotenv
from utils.subprocess_operations import get_piped_stdout
from utils.subprocess_operations import get_piped_stdout, stdout_to_quota_records
from hooks.slack import send_slack_message

load_dotenv()

Expand All @@ -17,9 +18,11 @@ def get_fileset_quota(project_id: str) -> str:


def monitor():
...
for project_id in PROJECT_IDs:
raw_quota = get_fileset_quota(project_id)
quota_record = stdout_to_quota_records(raw_quota)
send_slack_message(data=quota_record, webhook=SLACK_WEBHOOK)


if __name__ == "__main__":
for project_id in PROJECT_IDs:
print(get_fileset_quota(project_id))
monitor()
21 changes: 19 additions & 2 deletions utils/subprocess_operations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import subprocess
from itertools import zip_longest
from typing import Optional

JOB_RECORDS = list[dict[str, str]]
JOB_RECORD = dict[str, str]
JOB_RECORDS = list[JOB_RECORD]
QUOTA_RECORD = dict[str, str]
QUOTA_RECORDS = list(QUOTA_RECORD)


def get_cmd_stdout(command: str) -> str:
Expand All @@ -20,7 +24,8 @@ def get_piped_stdout(main_command: str, piped_command: str) -> Optional[str]:

if initial_command_result.returncode == 0:
initial_stdout = initial_command_result.stdout
piped_result = subprocess.run(piped_command.split(" "), input=initial_stdout, stdout=subprocess.PIPE, text=True, check=False)
piped_result = subprocess.run(piped_command.split(" "), input=initial_stdout, stdout=subprocess.PIPE, text=True,
check=False)

if piped_result.returncode == 0:
return piped_result.stdout
Expand All @@ -45,3 +50,15 @@ def stdout_to_job_records(s: str) -> JOB_RECORDS:
job_records.append(d)

return job_records


def stdout_to_quota_records(s: str) -> QUOTA_RECORD:
s = s.strip()
s_list = s.split()
headers = ["FileSet", "Used Storage (GB)", "Storage Limit (GB)", "Current File Number", "File Number Limit"]
quota_record = {}
assert len(s_list) == len(
headers), f"unexpected error: quota size different from headers size. quota: {s_list}, headers: {headers}"
for header, quota in zip_longest(headers, s_list[1:]):
quota_record[header] = quota
return quota_record

0 comments on commit 6c51ca0

Please sign in to comment.