Skip to content

Commit

Permalink
Merge pull request #495 from opensafely-core/fix-depenency-failed-mis…
Browse files Browse the repository at this point in the history
…sing-error-state

fix: make DEPENDENCY_FAILED spans with the error state
  • Loading branch information
bloodearnest authored Oct 21, 2022
2 parents 4ee59fe + 79c0a53 commit 4eafda0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions jobrunner/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def handle_single_job(job, api):
"for users to fix.\n"
"The tech team are automatically notified of these errors and will be "
"investigating.",
exc=exc,
error=exc,
)
# Do not clean up, as we may want to debug
#
Expand Down Expand Up @@ -222,6 +222,7 @@ def handle_job(job, api, mode=None, paused=None):
job,
StatusCode.DEPENDENCY_FAILED,
"Not starting as dependency failed",
error=True,
)
return

Expand Down Expand Up @@ -455,11 +456,11 @@ def get_states_of_awaited_jobs(job):
return states


def mark_job_as_failed(job, code, message=None, exc=None, **attrs):
def mark_job_as_failed(job, code, message=None, error=None, **attrs):
if message is None:
message = f"{type(exc).__name__}: {exc}"
message = str(error)

set_state(job, State.FAILED, code, message, error=exc, attrs=attrs)
set_state(job, State.FAILED, code, message, error=error, attrs=attrs)


def set_state(job, state, code, message, error=None, **attrs):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def test_handle_job_pending_dependency_failed(db):
spans = get_trace()
assert spans[-3].name == "CREATED"
assert spans[-2].name == "DEPENDENCY_FAILED"
assert spans[-2].status.status_code == trace.StatusCode.ERROR
assert spans[-1].name == "JOB"
assert spans[-1].status.status_code == trace.StatusCode.ERROR


def test_handle_pending_job_waiting_on_dependency(db):
Expand Down

0 comments on commit 4eafda0

Please sign in to comment.