Skip to content

Commit

Permalink
Delay calculation of failures in safe_run_hooks to simplify code
Browse files Browse the repository at this point in the history
If it isn't apparent, I'm trying to reduce the need for tracking variables
to make it easier extract the execution code to a separate private function
to make it easier to see what is happening.
  • Loading branch information
QMalcolm committed Oct 29, 2024
1 parent 4cd3e52 commit 5e9d3d6
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions core/dbt/task/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,6 @@ def safe_run_hooks(
hook_name = f"{hook.package_name}.{hook_type}.{hook.index - 1}"
execution_time = 0.0
timing: List[TimingInfo] = []
failures = 1

if status == RunStatus.Success:
with collect_timing_info("compile", timing.append):
Expand Down Expand Up @@ -681,7 +680,6 @@ def safe_run_hooks(
finished_at = timing[1].completed_at or datetime.utcnow()
hook.update_event_status(finished_at=finished_at.isoformat())
execution_time = (finished_at - started_at).total_seconds()
failures = 0 if status == RunStatus.Success else 1

if status == RunStatus.Success:
message = f"{hook_name} passed"
Expand All @@ -701,7 +699,7 @@ def safe_run_hooks(
message=message,
adapter_response={},
execution_time=execution_time,
failures=failures,
failures=0 if status == RunStatus.Success else 1,
node=hook,
)
)
Expand Down

0 comments on commit 5e9d3d6

Please sign in to comment.