Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staged pbs qstat #326

Merged
merged 8 commits into from
Mar 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions balsam/platform/scheduler/pbs_sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,7 @@ def _render_submit_args(

@staticmethod
def _render_status_args(project: Optional[str], user: Optional[str], queue: Optional[str]) -> List[str]:
args = [PBSScheduler.status_exe]
args += "-f -F json".split()
# if user is not None:
# args += ["-u", user]
if queue is not None:
args += ["-q", queue]
return args
pass

@staticmethod
def _render_delete_args(job_id: Union[int, str]) -> List[str]:
Expand All @@ -172,6 +166,29 @@ def _parse_submit_output(submit_output: str) -> int:
logger.warning(f"Exception: {exc}")
raise

@classmethod
def get_statuses(
cls,
project: Optional[str] = None,
user: Optional[str] = getpass.getuser(),
queue: Optional[str] = None,
) -> Dict[int, SchedulerJobStatus]:
# First call qstat to get user job ids
args = [PBSScheduler.status_exe]
stdout = scheduler_subproc(args)
stdout_lines = [s for s in stdout.split("\n") if str(user) in s]
if len(stdout_lines) == 0:
return {} # if there are no jobs in the queue return an empty dictionary
user_job_ids = [s.split(".")[0] for s in stdout_lines]

# Next call qstat to get job jsons
args = [PBSScheduler.status_exe]
args += user_job_ids
args += "-f -F json".split()
stdout = scheduler_subproc(args)
stat_dict = cls._parse_status_output(stdout)
return stat_dict

@staticmethod
def _parse_status_output(raw_output: str) -> Dict[int, SchedulerJobStatus]:
# TODO: this can be much more efficient with a compiled regex findall()
Expand Down