Skip to content

Commit

Permalink
Merge pull request #63 from ssciwr/runner_use_last_line_of_failed_scr…
Browse files Browse the repository at this point in the history
…ipt_as_error_message

Runner uploads last line of script output as error message if script …
  • Loading branch information
lkeegan authored Dec 18, 2024
2 parents 0a8ad33 + c9a63b0 commit 4ca7c34
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions backend/src/predicTCR_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def admin_resubmit_sample(sample_id: int):
sample.trusted_user_result_file_path().unlink(missing_ok=True)
sample.admin_result_file_path().unlink(missing_ok=True)
sample.has_results_zip = False
sample.error_message = ""
sample.status = Status.QUEUED
db.session.commit()
return jsonify(message="Sample added to the queue")
Expand Down
4 changes: 4 additions & 0 deletions backend/src/predicTCR_server/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Sample(db.Model):
timestamp_job_end: Mapped[int] = mapped_column(Integer, nullable=False)
status: Mapped[Status] = mapped_column(Enum(Status), nullable=False)
has_results_zip: Mapped[bool] = mapped_column(Boolean, nullable=False)
error_message: Mapped[str] = mapped_column(String, nullable=False)

def base_path(self) -> pathlib.Path:
data_path = flask.current_app.config["PREDICTCR_DATA_PATH"]
Expand Down Expand Up @@ -216,9 +217,11 @@ def process_result(
job.timestamp_end = timestamp_now()
if success:
job.status = Status.COMPLETED
sample.error_message = ""
else:
job.status = Status.FAILED
job.error_message = error_message
sample.error_message = error_message
db.session.commit()
if sample.has_results_zip:
logger.warning(f" --> Sample {sample_id} already has results")
Expand Down Expand Up @@ -503,6 +506,7 @@ def add_new_sample(
timestamp_job_end=0,
status=Status.QUEUED,
has_results_zip=False,
error_message="",
)
db.session.add(new_sample)
db.session.commit()
Expand Down
1 change: 1 addition & 0 deletions backend/tests/helpers/flask_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def add_test_samples(app, data_path: pathlib.Path):
timestamp_job_end=0,
status=status,
has_results_zip=False,
error_message="",
)
db.session.add(new_sample)
db.session.commit()
2 changes: 2 additions & 0 deletions frontend/src/components/SamplesTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function download_samples_as_csv() {
<fwb-table-head-cell v-if="admin">Runtime</fwb-table-head-cell>
<fwb-table-head-cell>Inputs</fwb-table-head-cell>
<fwb-table-head-cell>Results</fwb-table-head-cell>
<fwb-table-head-cell>Error message</fwb-table-head-cell>
<fwb-table-head-cell v-if="admin">Actions</fwb-table-head-cell>
</fwb-table-head>
<fwb-table-body>
Expand Down Expand Up @@ -155,6 +156,7 @@ function download_samples_as_csv() {
</template>
<template v-else> - </template>
</fwb-table-cell>
<fwb-table-cell>{{ sample.error_message }}</fwb-table-cell>
<fwb-table-cell v-if="admin">
<fwb-button
@click="
Expand Down
1 change: 1 addition & 0 deletions frontend/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type Sample = {
timestamp_job_end: number;
status: string;
has_results_zip: boolean;
error_message: string;
};

export type User = {
Expand Down
20 changes: 17 additions & 3 deletions runner/src/predicTCR_runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def _upload_result(
user_results: str,
trusted_user_results: str,
admin_results: str,
error_message: str,
):
self.logger.info(
f"...job {self.job_id} {'complete' if success else 'failed'} for sample id {self.sample_id}, uploading {user_results}, {trusted_user_results} and {admin_results}..."
Expand All @@ -93,6 +94,7 @@ def _upload_result(
"sample_id": self.sample_id,
"runner_hostname": self.runner_hostname,
"success": success,
"error_message": error_message,
},
headers=self.auth_header,
timeout=30,
Expand All @@ -118,8 +120,7 @@ def _run_job(self):
f"Failed to download {input_file_type}: {response.content}"
)
return self._report_job_failed(
f"Failed to download {input_file_type} on {self.runner_hostname}",
"",
f"Failed to download {input_file_type} on {self.runner_hostname}"
)
input_file_name = f"input.{input_file_type}"
self.logger.debug(f" - writing {input_file_name} to {tmpdir}...")
Expand All @@ -141,8 +142,20 @@ def _run_job(self):
for result_folder in result_folders:
(pathlib.Path(tmpdir) / result_folder).mkdir(exist_ok=True)
self.logger.debug(f" - running {tmpdir}/script.sh...")
proc = subprocess.run(args=["./script.sh"], cwd=tmpdir)
script_output_last_line = ""
with subprocess.Popen(
args=["./script.sh"],
cwd=tmpdir,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
universal_newlines=True,
) as proc:
for line in proc.stdout:
script_output_last_line = line.strip()
self.logger.debug(f"./script.sh :: {script_output_last_line}")
success = proc.returncode == 0
error_message = script_output_last_line if not success else ""
self.logger.debug(
f" ...{tmpdir}/script.sh {'finished' if success else 'failed'}."
)
Expand All @@ -154,6 +167,7 @@ def _run_job(self):
admin_results=f"{tmpdir}/admin_results.zip",
trusted_user_results=f"{tmpdir}/trusted_user_results.zip",
user_results=f"{tmpdir}/user_results.zip",
error_message=error_message,
)
self.poll_interval = 1
except Exception as e:
Expand Down

0 comments on commit 4ca7c34

Please sign in to comment.