forked from dptech-corp/dflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_error_handling.py
99 lines (85 loc) · 1.96 KB
/
test_error_handling.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from dflow import (
Workflow,
Step,
upload_artifact,
download_artifact
)
from dflow.python import (
PythonOPTemplate,
OP,
OPIO,
OPIOSign,
Artifact,
TransientError,
FatalError
)
from pathlib import Path
import time
class Hello(OP):
def __init__(self):
pass
@classmethod
def get_input_sign(cls):
return OPIOSign()
@classmethod
def get_output_sign(cls):
return OPIOSign()
@OP.exec_sign_check
def execute(
self,
op_in : OPIO,
) -> OPIO:
raise TransientError("Hello")
return OPIO()
class Timeout(OP):
def __init__(self):
pass
@classmethod
def get_input_sign(cls):
return OPIOSign()
@classmethod
def get_output_sign(cls):
return OPIOSign()
@OP.exec_sign_check
def execute(
self,
op_in : OPIO,
) -> OPIO:
time.sleep(100)
return OPIO()
class Goodbye(OP):
def __init__(self):
pass
@classmethod
def get_input_sign(cls):
return OPIOSign()
@classmethod
def get_output_sign(cls):
return OPIOSign()
@OP.exec_sign_check
def execute(
self,
op_in : OPIO,
) -> OPIO:
raise FatalError("Goodbye")
return OPIO()
if __name__ == "__main__":
wf = Workflow(name="hello")
step = Step(
name="hello0",
template=PythonOPTemplate(Hello, image="dptechnology/dflow", retry_on_transient_error=1),
continue_on_failed=True
)
wf.add(step)
step = Step(
name="hello1",
template=PythonOPTemplate(Timeout, image="dptechnology/dflow", timeout=10, retry_on_transient_error=1, timeout_as_transient_error=True),
continue_on_failed=True
)
wf.add(step)
step = Step(
name="hello2",
template=PythonOPTemplate(Goodbye, image="dptechnology/dflow", retry_on_transient_error=1)
)
wf.add(step)
wf.submit()