-
Notifications
You must be signed in to change notification settings - Fork 42
/
test_error_handling.py
95 lines (76 loc) · 1.95 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
import time
from dflow import Step, Workflow
from dflow.python import (OP, OPIO, FatalError, OPIOSign, PythonOPTemplate,
TransientError)
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="error-handling")
step = Step(
name="hello0",
template=PythonOPTemplate(
Hello, image="python:3.8", retry_on_transient_error=1),
continue_on_failed=True
)
wf.add(step)
step = Step(
name="hello1",
template=PythonOPTemplate(Timeout, image="python:3.8", 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="python:3.8", retry_on_transient_error=1)
)
wf.add(step)
wf.submit()