Skip to content

Commit

Permalink
Merge pull request #49 from JulianFP/dev
Browse files Browse the repository at this point in the history
Expose last line of error message of failed jobs to clients
  • Loading branch information
JulianFP authored Oct 26, 2024
2 parents 640f649 + a2e4f97 commit 93d921f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
23 changes: 13 additions & 10 deletions project_W/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ def jobInfo():
:qparam jobIds: List of Job-IDs as a string, separated by commas, e.g. `2,4,5,6`.
:resjson string msg: Human-readable response message designed to be directly shown to users
:resjson string errorType: One of ``invalidRequest``, ``permission``, ``notInDatabase`` for this route. Refer to :ref:`error_types-label`
:resjson list_of_objects jobs: Info of all requested jobs. Each object can (but doesn't have to) contain the following fields: `jobId: integer`, `fileName: string`, `model: string`, `language: string`, `status: object that can contain the fields 'step: string', 'runner: integer', 'progress: float'`.
:resjson list_of_objects jobs: Info of all requested jobs. Each object can (but doesn't have to) contain the following fields: `jobId: integer`, `fileName: string`, `model: string`, `language: string`, `error_msg: string, only exists if this job is in failed state (and even then not always)`, `status: object that can contain the fields 'step: string', 'runner: integer', 'progress: float'`.
:status 200: Returning the requested job infos.
:status 400: With errorType ``invalidRequest``.
Expand Down Expand Up @@ -707,15 +707,18 @@ def jobInfo():
),
403,
)
result.append(
{
"jobId": job.id,
"fileName": job.file_name,
"model": job.model,
"language": job.language,
"status": runner_manager.status_dict(job),
}
)
jobDict = {
"jobId": job.id,
"fileName": job.file_name,
"model": job.model,
"language": job.language,
"status": runner_manager.status_dict(job),
}
if job.error_msg is not None:
# ffmpeg exceptions are really long, only return last line
seperatedMsg = job.error_msg.strip().rsplit("\n", 1)
jobDict["error_msg"] = seperatedMsg[len(seperatedMsg) - 1]
result.append(jobDict)
return jsonify(msg="Returning requested jobs", jobs=result)

@app.post("/api/jobs/abort")
Expand Down
16 changes: 16 additions & 0 deletions tests/test_job_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,22 @@ def test_jobInfo_valid(client: Client, user, admin):
assert len(res.json["jobs"]) == 2


@pytest.mark.parametrize("client", [("[]", "false")], indirect=True)
def test_jobInfo_valid_failedJob(client: Client, user, admin):
res = client.post("api/jobs/abort", headers=user, data={"jobIds": 2})
assert res.status_code == 200

res = client.get("/api/jobs/info", headers=user, query_string={"jobIds": 2})
assert res.status_code == 200
assert res.json["msg"] == "Returning requested jobs"
assert res.json["jobs"][0]["error_msg"] == "job was aborted"

res = client.get("/api/jobs/info", headers=admin, query_string={"jobIds": 2})
assert res.status_code == 200
assert res.json["msg"] == "Returning requested jobs"
assert res.json["jobs"][0]["error_msg"] == "job was aborted"


@pytest.mark.parametrize("client", [("[]", "false")], indirect=True)
def test_abort_valid1(client: Client, user):
res = client.post("api/jobs/abort", headers=user, data={"jobIds": 2})
Expand Down

0 comments on commit 93d921f

Please sign in to comment.