Skip to content

Commit ab7478c

Browse files
committed
🎯 feat: passing execution time info on the result.
1 parent fcab02c commit ab7478c

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/ddeutil/workflow/audits.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
get_audit_model: Factory function for creating audit instances
2121
2222
Example:
23+
2324
```python
2425
from ddeutil.workflow.audits import get_audit_model
2526
26-
# Create file-based audit
27+
# NOTE: Create file-based Audit.
2728
audit = get_audit_model(run_id="run-123")
2829
audit.info("Workflow execution started")
2930
audit.success("Workflow completed successfully")

src/ddeutil/workflow/job.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ def execute(
773773
Returns
774774
Result: Return Result object that create from execution context.
775775
"""
776+
ts: float = time.monotonic()
776777
parent_run_id: str = run_id
777778
run_id: str = gen_id((self.id or "EMPTY"), unique=True)
778779
trace: Trace = get_trace(
@@ -790,7 +791,7 @@ def execute(
790791
params,
791792
run_id=parent_run_id,
792793
event=event,
793-
)
794+
).make_info({"execution_time": time.monotonic() - ts})
794795
elif self.runs_on.type == SELF_HOSTED: # pragma: no cov
795796
pass
796797
elif self.runs_on.type == AZ_BATCH: # pragma: no cov
@@ -802,7 +803,7 @@ def execute(
802803
run_id=run_id,
803804
parent_run_id=parent_run_id,
804805
event=event,
805-
)
806+
).make_info({"execution_time": time.monotonic() - ts})
806807

807808
trace.error(
808809
f"[JOB]: Execution not support runs-on: {self.runs_on.type.value!r} "
@@ -819,6 +820,8 @@ def execute(
819820
f"not support yet."
820821
).to_dict(),
821822
},
823+
info={"execution_time": time.monotonic() - ts},
824+
extras=self.extras,
822825
)
823826

824827

@@ -1010,6 +1013,7 @@ def local_execute(
10101013
10111014
:rtype: Result
10121015
"""
1016+
ts: float = time.monotonic()
10131017
parent_run_id: StrOrNone = run_id
10141018
run_id: str = gen_id((job.id or "EMPTY"), unique=True)
10151019
trace: Trace = get_trace(
@@ -1028,6 +1032,7 @@ def local_execute(
10281032
parent_run_id=parent_run_id,
10291033
status=SKIP,
10301034
context=catch(context, status=SKIP),
1035+
info={"execution_time": time.monotonic() - ts},
10311036
extras=job.extras,
10321037
)
10331038

@@ -1056,6 +1061,7 @@ def local_execute(
10561061
).to_dict()
10571062
},
10581063
),
1064+
info={"execution_time": time.monotonic() - ts},
10591065
extras=job.extras,
10601066
)
10611067

@@ -1127,6 +1133,7 @@ def local_execute(
11271133
parent_run_id=parent_run_id,
11281134
status=status,
11291135
context=catch(context, status=status, updated=errors),
1136+
info={"execution_time": time.monotonic() - ts},
11301137
extras=job.extras,
11311138
)
11321139

src/ddeutil/workflow/workflow.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def release(
460460
context=context,
461461
parent_run_id=parent_run_id,
462462
run_id=run_id,
463-
execution_time=99,
463+
execution_time=rs.info.get("execution_time", 0),
464464
extras=self.extras,
465465
).save(excluded=excluded)
466466
)
@@ -656,6 +656,7 @@ def execute(
656656
parent_run_id=parent_run_id,
657657
status=SUCCESS,
658658
context=catch(context, status=SUCCESS),
659+
info={"execution_time": time.monotonic() - ts},
659660
extras=self.extras,
660661
)
661662

@@ -687,6 +688,7 @@ def execute(
687688
).to_dict(),
688689
},
689690
),
691+
info={"execution_time": time.monotonic() - ts},
690692
extras=self.extras,
691693
)
692694

@@ -729,6 +731,7 @@ def execute(
729731
).to_dict(),
730732
},
731733
),
734+
info={"execution_time": time.monotonic() - ts},
732735
extras=self.extras,
733736
)
734737
elif check == SKIP: # pragma: no cov
@@ -812,6 +815,7 @@ def execute(
812815
parent_run_id=parent_run_id,
813816
status=st,
814817
context=catch(context, status=st),
818+
info={"execution_time": time.monotonic() - ts},
815819
extras=self.extras,
816820
)
817821

@@ -840,6 +844,7 @@ def execute(
840844
).to_dict(),
841845
},
842846
),
847+
info={"execution_time": time.monotonic() - ts},
843848
extras=self.extras,
844849
)
845850

0 commit comments

Comments
 (0)