/
dag.py
91 lines (48 loc) · 1.5 KB
/
dag.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
# type: ignore
from easydags import ExecNode, DAG
nodes = []
nodes.append( ExecNode(id_= 'f0',
exec_function = lambda : 0
) )
nodes.append( ExecNode(id_= 'f1',
exec_function = lambda : 1
) )
def aux(**kwargs):
f1 = kwargs['f1_result']
f0 = kwargs['f0_result']
return f1*2 + f0
nodes.append( ExecNode(id_= 'f2',
exec_function = aux,
depends_on_hard= ['f1','f0']) )
def aux2(**kwargs):
f2 = kwargs['f2_result']
return f2 * 2
nodes.append( ExecNode(id_= 'f3',
exec_function = aux2,
depends_on_hard = ['f2']) )
def aux3(**kwargs):
return 3
import random as rnd
def fail(**kwargs):
rnd_num = rnd.random()
if rnd_num > 0.9:
raise ValueError('This is a random error')
return kwargs
nodes.append( ExecNode(id_= 'f4',
exec_function = fail,
n_trials=1,
depends_on_soft= ['f3']) )
nodes.append( ExecNode(id_= 'f5',
exec_function = fail,
n_trials=1,
depends_on_hard= ['f3']) )
nodes.append( ExecNode(id_= 'f6',
exec_function = aux3,
depends_on_hard= ['f3', 'f4','f5']) )
def execute():
dag = DAG(nodes,name = 'Example DAG',max_concurrency=8, debug = False,error_type_fatal=False)
dag.execute()
print('###########################')
dag.execute()
if __name__ == "__main__":
dag = execute()