From 6005751f0230a16d979afe7e0255d4a975218a9e Mon Sep 17 00:00:00 2001 From: Rachel Chen Date: Sun, 29 Dec 2024 21:10:00 -0800 Subject: [PATCH 1/5] c --- snuba/admin/views.py | 15 ++++++++++++++- snuba/manual_jobs/runner.py | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/snuba/admin/views.py b/snuba/admin/views.py index d9447e470e..e771304f48 100644 --- a/snuba/admin/views.py +++ b/snuba/admin/views.py @@ -1369,7 +1369,20 @@ def get_job_specs() -> Response: @check_tool_perms(tools=[AdminTools.MANUAL_JOBS]) def execute_job(job_id: str) -> Response: job_specs = list_job_specs() - return make_response(run_job(job_specs[job_id]), 200) + job_status = None + try: + job_status = run_job(job_specs[job_id]) + except BaseException as e: + return make_response( + jsonify( + { + "error": str(e), + } + ), + 500, + ) + + return make_response(job_status, 200) @application.route("/job-specs//logs", methods=["GET"]) diff --git a/snuba/manual_jobs/runner.py b/snuba/manual_jobs/runner.py index 6ddd3258f7..55ebaa99b0 100644 --- a/snuba/manual_jobs/runner.py +++ b/snuba/manual_jobs/runner.py @@ -138,6 +138,7 @@ def run_job(job_spec: JobSpec) -> JobStatus: current_job_status = _set_job_status(job_spec.job_id, JobStatus.FAILED) job_logger.error(f"[runner] job execution failed {e}") job_logger.info(f"[runner] exception {traceback.format_exc()}") + raise e finally: _release_job_lock(job_spec.job_id) From bc377b87f8e08bd54eb63b83558dfed7a296f29e Mon Sep 17 00:00:00 2001 From: Rachel Chen Date: Fri, 3 Jan 2025 16:08:23 -0800 Subject: [PATCH 2/5] exception --- snuba/manual_jobs/runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snuba/manual_jobs/runner.py b/snuba/manual_jobs/runner.py index 55ebaa99b0..b9e336125f 100644 --- a/snuba/manual_jobs/runner.py +++ b/snuba/manual_jobs/runner.py @@ -134,7 +134,7 @@ def run_job(job_spec: JobSpec) -> JobStatus: if not job_spec.is_async: current_job_status = _set_job_status(job_spec.job_id, JobStatus.FINISHED) job_logger.info("[runner] job execution finished") - except BaseException as e: + except Exception as e: current_job_status = _set_job_status(job_spec.job_id, JobStatus.FAILED) job_logger.error(f"[runner] job execution failed {e}") job_logger.info(f"[runner] exception {traceback.format_exc()}") From 061ab41af800c8d660d40ee63096649994194c46 Mon Sep 17 00:00:00 2001 From: Rachel Chen Date: Fri, 3 Jan 2025 16:26:48 -0800 Subject: [PATCH 3/5] Trigger Build From bc14607f2f86cf3c1c082b3ca275cc481fddd382 Mon Sep 17 00:00:00 2001 From: Rachel Chen Date: Sun, 5 Jan 2025 18:21:15 -0800 Subject: [PATCH 4/5] fixed --- tests/manual_jobs/test_job_statuses.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/manual_jobs/test_job_statuses.py b/tests/manual_jobs/test_job_statuses.py index f1e6083514..3268ecd782 100644 --- a/tests/manual_jobs/test_job_statuses.py +++ b/tests/manual_jobs/test_job_statuses.py @@ -45,7 +45,8 @@ def test_job_with_exception_causes_failure() -> None: with patch.object(_JobLoader, "get_job_instance") as MockGetInstance: MockGetInstance.return_value = FailJob() assert get_job_status(JOB_ID) == JobStatus.NOT_STARTED - run_job(test_job_spec) + with pytest.raises(SerializableException): + run_job(test_job_spec) assert get_job_status(JOB_ID) == JobStatus.FAILED From 7bbbcc4734a47624ccf5e0580612f45e1ba79a44 Mon Sep 17 00:00:00 2001 From: Rachel Chen Date: Mon, 6 Jan 2025 11:06:36 -0800 Subject: [PATCH 5/5] exception type --- snuba/manual_jobs/runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snuba/manual_jobs/runner.py b/snuba/manual_jobs/runner.py index b9e336125f..55ebaa99b0 100644 --- a/snuba/manual_jobs/runner.py +++ b/snuba/manual_jobs/runner.py @@ -134,7 +134,7 @@ def run_job(job_spec: JobSpec) -> JobStatus: if not job_spec.is_async: current_job_status = _set_job_status(job_spec.job_id, JobStatus.FINISHED) job_logger.info("[runner] job execution finished") - except Exception as e: + except BaseException as e: current_job_status = _set_job_status(job_spec.job_id, JobStatus.FAILED) job_logger.error(f"[runner] job execution failed {e}") job_logger.info(f"[runner] exception {traceback.format_exc()}")