Skip to content

Commit

Permalink
Merge branch 'RESTAPI-1150-polling-output' into 'master'
Browse files Browse the repository at this point in the history
Return empty `job_data_out` and `job_file_err` while job is pending

See merge request firecrest/firecrest!308
  • Loading branch information
ekouts committed Jul 29, 2024
2 parents 45c8f7e + a93b887 commit 844d604
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fix parsing in `GET /utilities/ls` endpoint.
- The job fields `job_data_out` and `job_file_err` from `GET /compute/jobs` will be empty for jobs that are still pending (so that there is no confusion with older output/error files).

## [1.16.0]

Expand Down
8 changes: 8 additions & 0 deletions src/common/schedulers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def job_info(self, jobid):
* Job output filename
* Job error filename
* Job script filename
* Job state
"""
pass

Expand All @@ -104,6 +105,7 @@ def parse_job_info(self, output):
* Job output filename
* Job error filename
* Job script filename
* Job state
"""
pass

Expand Down Expand Up @@ -202,3 +204,9 @@ def check_job_time(self, job_time):
* DD-HH DD-HH:MM
* DD-HH:MM:SS
"""

@abc.abstractmethod
def job_is_pending(self, state):
"""Check if the job is pending based on the state.
"""
pass
12 changes: 12 additions & 0 deletions src/common/schedulers/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,15 @@ def check_job_time(self, job_time):
logger.error(e, exc_info=True)

return False

def job_is_pending(self, state):
# Complete list in Slurm's documentation:
# https://slurm.schedmd.com/squeue.html#SECTION_JOB-STATE-CODES
pending_states = {
'CONFIGURING',
'PENDING'
}
if state:
return any(s in pending_states for s in state.split(','))

return False
7 changes: 5 additions & 2 deletions src/compute/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,11 @@ def get_job_files(headers, system_name, system_addr, job_info, output=False, use
control_info["job_file"] = control_dict.get("Command", "command-not-found")
control_info["job_data_out"] = ""
control_info["job_data_err"] = ""
state = control_dict.get("JobState", "UNKNOWN")

if output:
# Return empty output if the job is pending, since the files may belong
# to an older job
if output and not scheduler.job_is_pending(state):
# to add data from StdOut and StdErr files in Task
# this is done when GET compute/jobs is triggered.
#
Expand Down Expand Up @@ -741,7 +744,7 @@ def list_job_task(headers,system_name, system_addr,action,task_id,pageSize,pageN
jobs = {}
for job_index, jobinfo in enumerate(jobList):
# now looking for log and err files location
jobinfo = get_job_files(headers, system_name, system_addr, jobinfo, True)
jobinfo = get_job_files(headers, system_name, system_addr, jobinfo, output=True)

# add jobinfo to the array
jobs[str(job_index)]=jobinfo
Expand Down

0 comments on commit 844d604

Please sign in to comment.