-
Notifications
You must be signed in to change notification settings - Fork 16
/
02-passing-data.py
74 lines (52 loc) · 1.73 KB
/
02-passing-data.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
from liteflow.core import *
class Hello(StepBody):
def run(self, context: StepExecutionContext) -> ExecutionResult:
print("Hello world")
return ExecutionResult.next()
class Goodbye(StepBody):
def run(self, context: StepExecutionContext) -> ExecutionResult:
print("Goodbye")
return ExecutionResult.next()
class AddNumbers(StepBody):
def __init__(self):
self.input1 = 0
self.input2 = 0
self.output = 0
def run(self, context: StepExecutionContext) -> ExecutionResult:
self.output = self.input1 + self.input2
return ExecutionResult.next()
class PrintMessage(StepBody):
def __init__(self):
self.message = ""
def run(self, context: StepExecutionContext) -> ExecutionResult:
print(self.message)
return ExecutionResult.next()
class MyData:
def __init__(self):
self.value1 = 0
self.value2 = 0
self.value3 = 0
class MyWorkflow(Workflow):
def id(self):
return "MyWorkflow"
def version(self):
return 1
def build(self, builder: WorkflowBuilder):
builder\
.start_with(Hello)\
.then(AddNumbers) \
.input('input1', lambda data, context: data.value1) \
.input('input2', lambda data, context: data.value2) \
.output('value3', lambda step: step.output) \
.then(PrintMessage) \
.input('message', lambda data, context: "The answer is %s" % data.value3) \
.then(Goodbye)
host = configure_workflow_host()
host.register_workflow(MyWorkflow())
host.start()
data = MyData()
data.value1 = 2
data.value2 = 3
wid = host.start_workflow("MyWorkflow", 1, data)
input()
host.stop()