Skip to content

Commit f5779a0

Browse files
committed
🎨 format: move to use from_trace method.
1 parent b6e0ee5 commit f5779a0

4 files changed

Lines changed: 35 additions & 35 deletions

File tree

src/ddeutil/workflow/conf.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def trace_handlers(self) -> list[dict[str, Any]]:
117117
def debug(self) -> bool:
118118
"""Debug flag for echo log that use DEBUG mode.
119119
120-
:rtype: bool
120+
Returns: bool
121121
"""
122122
return str2bool(env("LOG_DEBUG_MODE", "true"))
123123

@@ -472,9 +472,11 @@ def dynamic(
472472
def pass_env(value: T) -> T: # pragma: no cov
473473
"""Passing environment variable to an input value.
474474
475-
:param value: (Any) A value that want to pass env var searching.
475+
Args:
476+
value (Any): A value that want to pass env var searching.
476477
477-
:rtype: Any
478+
Returns:
479+
Any: An any value that have passed environment variable.
478480
"""
479481
if isinstance(value, dict):
480482
return {k: pass_env(value[k]) for k in value}

src/ddeutil/workflow/result.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,19 @@ class Info(TypedDict):
283283
exec_latency: NotRequired[float]
284284

285285

286+
class System(TypedDict):
287+
__sys_release_dryrun_mode: NotRequired[bool]
288+
__sys_exec_break_circle: NotRequired[str]
289+
290+
286291
class Context(TypedDict):
287292
"""Context dict typed."""
288293

289294
status: Status
295+
info: Info
296+
sys: NotRequired[System]
290297
context: NotRequired[DictData]
291298
errors: NotRequired[Union[list[ErrorData], ErrorData]]
292-
info: NotRequired[DictData]
293299

294300

295301
class Layer(str, Enum):

src/ddeutil/workflow/stages.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,11 @@ def execute(
398398
f"💥 Error Failed:||🚨 {traceback.format_exc()}||",
399399
module="stage",
400400
)
401-
return Result(
402-
run_id=run_id,
403-
parent_run_id=parent_run_id,
401+
return Result.from_trace(trace).catch(
404402
status=FAILED,
405403
context=catch(
406404
context, status=FAILED, updated={"errors": to_dict(e)}
407405
),
408-
extras=self.extras,
409406
)
410407
finally:
411408
context["info"].update(
@@ -857,25 +854,20 @@ async def axecute(
857854
f"[STAGE]: 🤫 Stage Failed with disable traceback:||{e}"
858855
)
859856
st: Status = get_status_from_error(e)
860-
return Result(
861-
run_id=run_id,
862-
parent_run_id=parent_run_id,
857+
return Result.from_trace(trace).catch(
863858
status=st,
864859
context=catch(context, status=st, updated=updated),
865-
extras=self.extras,
866860
)
867861
except Exception as e:
868862
await trace.aerror(
869-
f"[STAGE]:💥 Error Failed:||🚨 {traceback.format_exc()}||"
863+
f"💥 Error Failed:||🚨 {traceback.format_exc()}||",
864+
module="stage",
870865
)
871-
return Result(
872-
run_id=run_id,
873-
parent_run_id=parent_run_id,
866+
return Result.from_trace(trace).catch(
874867
status=FAILED,
875868
context=catch(
876869
context, status=FAILED, updated={"errors": to_dict(e)}
877870
),
878-
extras=self.extras,
879871
)
880872
finally:
881873
context["info"].update(

src/ddeutil/workflow/workflow.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
Constants:
2020
NORMAL: Normal release execution
2121
RERUN: Re-execution of failed workflows
22-
EVENT: Event-triggered execution
22+
DRYRUN: Dryrun execution for testing workflow loop.
2323
FORCE: Force execution regardless of conditions
2424
"""
2525
import copy
2626
import time
27+
import traceback
2728
from concurrent.futures import (
2829
Future,
2930
ThreadPoolExecutor,
@@ -50,6 +51,7 @@
5051
WorkflowError,
5152
WorkflowSkipError,
5253
WorkflowTimeoutError,
54+
to_dict,
5355
)
5456
from .event import Event
5557
from .job import Job
@@ -667,22 +669,9 @@ def process(
667669

668670
if check == FAILED: # pragma: no cov
669671
pop_sys_extras(self.extras)
670-
return Result(
671-
run_id=run_id,
672-
parent_run_id=parent_run_id,
673-
status=FAILED,
674-
context=catch(
675-
context,
676-
status=FAILED,
677-
updated={
678-
"status": FAILED,
679-
"errors": WorkflowError(
680-
f"Validate job trigger rule was failed "
681-
f"with {job.trigger_rule.value!r}."
682-
).to_dict(),
683-
},
684-
),
685-
extras=self.extras,
672+
raise WorkflowError(
673+
f"Validate job trigger rule was failed with "
674+
f"{job.trigger_rule.value!r}."
686675
)
687676
elif check == SKIP: # pragma: no cov
688677
trace.info(
@@ -1026,12 +1015,23 @@ def execute(
10261015
trace.error(f"⏭️ Skip: {e}", module="workflow")
10271016
updated = None
10281017
else:
1029-
trace.error(f"📢 Workflow Failed: {e}", module="workflow")
1018+
trace.error(f"📢 Workflow Failed:||{e}", module="workflow")
10301019

10311020
st: Status = get_status_from_error(e)
10321021
return Result.from_trace(trace).catch(
10331022
status=st, context=catch(context, status=st, updated=updated)
10341023
)
1024+
except Exception as e:
1025+
trace.error(
1026+
f"💥 Error Failed:||🚨 {traceback.format_exc()}||",
1027+
module="workflow",
1028+
)
1029+
return Result.from_trace(trace).catch(
1030+
status=FAILED,
1031+
context=catch(
1032+
context, status=FAILED, updated={"errors": to_dict(e)}
1033+
),
1034+
)
10351035
finally:
10361036
context["info"].update(
10371037
{

0 commit comments

Comments
 (0)