Skip to content

Commit 63140a2

Browse files
committed
chore: updated readme
1 parent 9c44f35 commit 63140a2

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

README.md

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919

2020
**Freak** is primarily composed of two components, Engine and Flow, which are further divided into smaller components. Engine is encapsulation of logic on how to read flows and execute them in order of specified definition. Engine does this using components:
2121

22-
- **Factory**
2322
- **Butler**
24-
- **Prosecutioner**
23+
- **Executor**
2524
- **Inspector**
2625

2726
Before explaining about these components, it is a good idea to understand what exactly is a flow in a Freak and how it is implemented. A flow is nothing but a set of steps intended to achieve an objective. This objective can be anything that is identifiable as business logic. The implementation of flow is done by defining three components:
@@ -30,15 +29,11 @@ Before explaining about these components, it is a good idea to understand what e
3029

3130
- **Locator**, it uses flow decorator to locate steps defined in a module (module here is used as reference to single python file). Every flow is required to define one of its own, so that `Butler` can use it to identify and execute the flow.
3231

33-
- **Organizer**, as the name suggests is responsible for organizing the steps of a flow. Every flow id required to define one of its own. Currently, only linear flow is implemented.
34-
3532
Since, we have a basic understanding of what exactly a flow in freak is, let's move on to engine components.
3633

37-
- **Factory** is responsible for collecting `Locator` and `Organizer` for defined flow. It works as input generator for `Butler`.
38-
39-
- **Butler** is responsible for reading python modules, locating steps and organizing them using locator and organizer provided by factory.
34+
- **Butler** is responsible for reading python modules, locating steps and organizing them using locator specified by flow.
4035

41-
- **Prosecutioner** is core component of the engine. It is responsible for executing steps. Currently, it only supports linear flows.
36+
- **Executor** is core component of the engine. It is responsible for executing steps. Currently, it only supports linear flows.
4237

4338
- **Inspector** is used to return input schema for every step defined by the flow. This is intended to be part of view logic of the engine.
4439

@@ -47,11 +42,11 @@ Since, we have a basic understanding of what exactly a flow in freak is, let's m
4742
This is how you define a flow using base flow.
4843

4944
```python
50-
from freak.engine import butler, inspector, prosecutioner
51-
from freak.flows.base_flow import base_flow, locator, organizer
45+
from freak.flows.base_flow import base_flow
5246
from freak.models.input import InputModel, InputModelB
5347
from freak.models.request import RequestContext
5448
from freak.models.response import Response, SuccessResponseContext
49+
from freak.types import Flow
5550

5651

5752
@base_flow(
@@ -122,22 +117,29 @@ def func_four(ctx: RequestContext) -> Response:
122117
Following test case will use above defintion to execute the flow.
123118

124119
```python
120+
from freak.engine import Engine
121+
125122
def test_base_flow_prosecutioner():
126-
output = prosecutioner(
127-
module_name=__name__,
128-
decorator_name="base_flow",
129-
data={"a": 4, "b": 7},
130-
)
123+
executioner = Engine(module_name=__name__, decorator_name="base_flow")
124+
125+
response = executioner.execute(data={"a": 4, "b": 7}, from_step="func_one")
126+
127+
output, path_traversed = response
128+
129+
assert path_traversed == {
130+
"last_step": "func_three",
131+
"traversed": {
132+
"func_one": ["func_two"],
133+
"func_two": ["func_three"],
134+
"func_three": ["func_four"],
135+
},
136+
}
131137

132138
responses = output.responses
133-
total_steps = output.to_step - output.from_step + 1
134139

135140
assert output.from_step == 1
136141
assert output.to_step == 4
137142

138-
assert total_steps == 4
139-
assert len(responses) == total_steps
140-
141143
assert output.last_successful_step == 3
142144

143145
assert responses[0].output == {"a": 5, "b": 9}
@@ -151,13 +153,14 @@ def test_base_flow_prosecutioner():
151153
== "Variable: c | Type: value_error.missing | Message: field required"
152154
)
153155

154-
output = prosecutioner(
155-
module_name=__name__,
156-
decorator_name="base_flow",
156+
response = executioner.execute(
157157
data={"a": 4, "b": 7, "c": 5},
158-
step=4,
158+
from_step="func_four",
159+
executed_steps=path_traversed,
159160
)
160161

162+
output, path_traversed = response
163+
161164
responses = output.responses
162165
assert len(responses) == 1
163166
assert responses[0].output == {"a": 8, "b": 12, "c": 11}
@@ -166,19 +169,25 @@ def test_base_flow_prosecutioner():
166169
assert output.from_step == 4
167170
assert output.to_step == 4
168171

172+
assert path_traversed == {
173+
"last_step": "func_four",
174+
"traversed": {
175+
"func_one": ["func_two"],
176+
"func_two": ["func_three"],
177+
"func_three": ["func_four"],
178+
"func_four": [],
179+
},
180+
}
169181
```
170182

171183
Using above code, it is also possible to generate input schema for every step. Following test case will demonstrate this behaviour.
172184

173185
```python
174-
175-
from freak.engine import inspector
186+
from freak.engine import Engine
176187

177188
def test_base_flow_fetch_schema():
178-
responses = inspector(
179-
module_name=__name__,
180-
decorator_name="base_flow",
181-
)
189+
executioner = Engine(module_name=__name__, decorator_name="base_flow")
190+
responses = executioner.inspect()
182191

183192
input_model_b_schema = {
184193
"title": "InputModelB",
@@ -191,7 +200,6 @@ def test_base_flow_fetch_schema():
191200
},
192201
"required": ["a", "b", "c"],
193202
}
194-
195203
input_model_schema = {
196204
"title": "InputModel",
197205
"description": "Class for defining structure of request data.",
@@ -203,11 +211,13 @@ def test_base_flow_fetch_schema():
203211
"required": ["a", "b"],
204212
}
205213

214+
assert input_model_schema == InputModel.schema()
215+
assert input_model_b_schema == InputModelB.schema()
216+
206217
assert responses[0]["schema"] == input_model_schema
207218
assert responses[1]["schema"] == input_model_schema
208219
assert responses[2]["schema"] == input_model_schema
209220
assert responses[3]["schema"] == input_model_b_schema
210-
211221
```
212222

213223
<!-- ## Very first steps

0 commit comments

Comments
 (0)