Skip to content

Commit 3150e21

Browse files
committed
Update command-line documentation to reflect changes in production naming and add new command options
1 parent 9f3b6dd commit 3150e21

File tree

2 files changed

+243
-30
lines changed

2 files changed

+243
-30
lines changed

docs/command-line.md

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,41 @@ iop
99

1010
output :
1111
```bash
12-
usage: python3 -m iop [-h] [-d DEFAULT] [-l] [-s START] [-k] [-S] [-r] [-M MIGRATE] [-e EXPORT] [-x] [-v] [-L]
12+
usage: python3 -m iop [-h] [-d DEFAULT] [-l] [-s START] [-S] [-k] [-r] [-x] [-m MIGRATE]
13+
[-e EXPORT] [-v] [-L] [-i INIT] [-t TEST] [-D] [-C CLASSNAME] [-B BODY]
14+
1315
optional arguments:
1416
-h, --help display help and default production name
1517
-d DEFAULT, --default DEFAULT
1618
set the default production
17-
-l, --lists list productions
19+
-l, --list list productions
1820
-s START, --start START
1921
start a production
20-
-k, --kill kill a production (force stop)
21-
-S, --stop stop a production
22-
-r, --restart restart a production
23-
-M MIGRATE, --migrate MIGRATE
22+
-S, --stop stop a production
23+
-k, --kill kill a production
24+
-r, --restart restart a production
25+
-x, --status status a production
26+
-m MIGRATE, -M MIGRATE, --migrate MIGRATE
2427
migrate production and classes with settings file
2528
-e EXPORT, --export EXPORT
2629
export a production
27-
-x, --status status a production
28-
-v, --version display version
29-
-L, --log display log
30-
31-
default production: PEX.Production
30+
-v, --version display version
31+
-L, --log display log
32+
-i INIT, --init INIT
33+
init the pex module in iris
34+
-t TEST, --test TEST
35+
test the pex module in iris
36+
37+
start arguments:
38+
-D, --detach start a production in detach mode
39+
40+
test arguments:
41+
-C CLASSNAME, --classname CLASSNAME
42+
test classname
43+
-B BODY, --body BODY
44+
test body
45+
46+
default production: IoP.Production
3247
```
3348

3449
## help
@@ -41,9 +56,10 @@ iop -h
4156

4257
output :
4358
```bash
44-
usage: python3 -m iop [-h] [-d DEFAULT] [-l] [-s START] [-k] [-S] [-r] [-M MIGRATE] [-e EXPORT] [-x] [-v] [-L]
59+
usage: python3 -m iop [-h] [-d DEFAULT] [-l] [-s START] [-S] [-k] [-r] [-x] [-m MIGRATE]
60+
[-e EXPORT] [-v] [-L] [-i INIT] [-t TEST] [-D] [-C CLASSNAME] [-B BODY]
4561
...
46-
default production: PEX.Production
62+
default production: IoP.Production
4763
```
4864

4965
## default
@@ -58,13 +74,13 @@ iop -d
5874

5975
output :
6076
```bash
61-
default production: PEX.Production
77+
default production: IoP.Production
6278
```
6379

6480
With an argument, it set the default production.
6581

6682
```bash
67-
iop -d PEX.Production
83+
iop -d IoP.Production
6884
```
6985

7086
## lists
@@ -78,7 +94,7 @@ iop -l
7894
output :
7995
```bash
8096
{
81-
"PEX.Production": {
97+
"IoP.Production": {
8298
"Status": "Stopped",
8399
"LastStartTime": "2023-05-31 11:13:51.000",
84100
"LastStopTime": "2023-05-31 11:13:54.153",
@@ -89,22 +105,22 @@ output :
89105

90106
## start
91107

92-
The start command start a production.
108+
The start command starts a production.
93109

94-
To exit the command, you have to press CTRL+C.
110+
To exit the command, you have to press CTRL+C (unless using detach mode).
95111

96112
```bash
97-
iop -s PEX.Production
113+
iop -s IoP.Production
98114
```
99115

100-
output :
116+
You can start a production in detach mode using the -D flag:
117+
101118
```bash
102-
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting production
103-
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting item Python.FileOperation
104-
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting item Python.EmailOperation
105-
...
119+
iop -s IoP.Production -D
106120
```
107121

122+
In detach mode, the production starts and the command returns immediately without showing logs.
123+
108124
## kill
109125

110126
The kill command kill a production (force stop).
@@ -151,6 +167,33 @@ iop -M /tmp/settings.py
151167

152168
More details about the settings file can be found [here](getting-started/register-component.md).
153169

170+
## init
171+
172+
The init command initializes the IoP module in IRIS.
173+
174+
```bash
175+
iop -i
176+
```
177+
178+
## test
179+
180+
The test command allows testing IoP components. You can optionally specify a test name, classname, and body.
181+
182+
Basic test:
183+
```bash
184+
iop -t
185+
```
186+
187+
Test with specific classname:
188+
```bash
189+
iop -t MyTest -C MyClass
190+
```
191+
192+
Test with body:
193+
```bash
194+
iop -t MyTest -C MyClass -B "test body"
195+
```
196+
154197
## export
155198

156199
The export command export a production.
@@ -164,14 +207,14 @@ iop -e
164207
If an argument is given, the export command export the production given in argument.
165208

166209
```bash
167-
iop -e PEX.Production
210+
iop -e IoP.Production
168211
```
169212

170213
output :
171214
```bash
172215
{
173216
"Production": {
174-
"@Name": "PEX.Production",
217+
"@Name": "IoP.Production",
175218
"@TestingEnabled": "true",
176219
"@LogGeneralTraceEvents": "false",
177220
"Description": "",
@@ -223,7 +266,7 @@ iop -x
223266
output :
224267
```bash
225268
{
226-
"Production": "PEX.Production",
269+
"Production": "IoP.Production",
227270
"Status": "stopped"
228271
}
229272
```
@@ -259,8 +302,8 @@ iop -L
259302

260303
output :
261304
```bash
262-
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting production
263-
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting item Python.FileOperation
264-
2021-08-30 15:13:51.000 [PEX.Production] INFO: Starting item Python.EmailOperation
305+
2021-08-30 15:13:51.000 [IoP.Production] INFO: Starting production
306+
2021-08-30 15:13:51.000 [IoP.Production] INFO: Starting item Python.FileOperation
307+
2021-08-30 15:13:51.000 [IoP.Production] INFO: Starting item Python.EmailOperation
265308
...
266309
```

docs/example.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,173 @@ Use the `iop` command line to register your component:
6464
```bash
6565
iop --migrate /path/to/your/project/setting.py
6666
```
67+
68+
## Business Service
69+
70+
Two kinds of business services can be created in Python:
71+
72+
- Business Service
73+
- Pulling Business Service
74+
75+
### Business Service
76+
77+
To create a business service, use the following code:
78+
79+
```python
80+
from iop import BusinessService
81+
82+
class MyBusinessService(BusinessService):
83+
84+
def on_process_input(self, message_input: 'MyRequest'):
85+
# This method is called when the service is called
86+
self.log_info("[Python] MyBusinessService:on_process_input() is called with message: " + message_input.request_string)
87+
response = MyResponse("MyBusinessService:on_process_input() echos")
88+
return response
89+
```
90+
91+
### Pulling Business Service
92+
93+
To create a business service that runs every 5 seconds, use the following code:
94+
95+
```python
96+
from iop import BusinessService
97+
98+
class MyBusinessService(BusinessService):
99+
100+
def get_adapter_type():
101+
# This is mandatory to schedule the service
102+
# By default, the service will be scheduled every 5 seconds
103+
return "Ens.InboundAdapter"
104+
105+
def on_process_input(self):
106+
# This method is called every 5 seconds
107+
self.log_info("[Python] MyBusinessService:on_process_input() is called")
108+
```
109+
110+
## Flask app sending a message to an Business Service
111+
112+
To send a message to a business service, use the following code:
113+
114+
115+
```python
116+
from flask import Flask, request
117+
from iop import Director
118+
119+
app = Flask(__name__)
120+
121+
director = Director()
122+
123+
@app.route('/send_message', methods=['POST'])
124+
def send_message():
125+
message = request.json
126+
bs = director.get_business_service("Python.MyBusinessService")
127+
resp = bs.on_process_input(message)
128+
return resp
129+
```
130+
131+
## Business Process
132+
133+
To create a business process, use the following code:
134+
135+
```python
136+
from iop import BusinessProcess
137+
138+
class MyBusinessProcess(BusinessProcess):
139+
140+
def on_message(self, message_input: 'MyRequest'):
141+
# Called from service/process/operation, message is of type MyRequest with property request_string
142+
self.log_info("[Python] MyBusinessProcess:on_message() is called with message: " + message_input.request_string)
143+
response = MyResponse("MyBusinessProcess:on_message() echos")
144+
return response
145+
```
146+
147+
### Async calls
148+
149+
There is three ways to make async calls in Python:
150+
151+
1. Using the `asyncio` library.
152+
2. Using the native `send_request_async` method.
153+
3. Using the `send_multi_request_sync` method.
154+
155+
#### Using the `asyncio` library
156+
157+
To make an async call with asyncio, use the following code:
158+
159+
```python
160+
import asyncio
161+
import random
162+
163+
from iop import BusinessProcess
164+
from msg import MyMessage
165+
166+
167+
class MyAsyncNGBP(BusinessProcess):
168+
169+
def on_message(self, request):
170+
171+
results = asyncio.run(self.await_response(request))
172+
173+
for result in results:
174+
self.log_info(f"Received response: {result.message}")
175+
176+
async def await_response(self, request):
177+
# create 1 to 10 messages
178+
tasks = []
179+
for i in range(random.randint(1, 10)):
180+
tasks.append(self.send_request_async_ng("Python.MyAsyncNGBO",
181+
MyMessage(message=f"Message {i}")))
182+
183+
return await asyncio.gather(*tasks)
184+
```
185+
186+
#### Using the native `send_request_async` method
187+
188+
To make an async call with the native `send_request_async` method, use the following code:
189+
190+
```python
191+
from grongier.pex import BusinessProcess
192+
from msg import MyMessage
193+
194+
195+
class MyBP(BusinessProcess):
196+
197+
def on_message(self, request):
198+
msg_one = MyMessage(message="Message1")
199+
msg_two = MyMessage(message="Message2")
200+
201+
self.send_request_async("Python.MyBO", msg_one,completion_key="1")
202+
self.send_request_async("Python.MyBO", msg_two,completion_key="2")
203+
204+
def on_response(self, request, response, call_request, call_response, completion_key):
205+
if completion_key == "1":
206+
self.response_one = call_response
207+
elif completion_key == "2":
208+
self.response_two = call_response
209+
210+
def on_complete(self, request, response):
211+
self.log_info(f"Received response one: {self.response_one.message}")
212+
self.log_info(f"Received response two: {self.response_two.message}")
213+
```
214+
215+
#### Using the `send_multi_request_sync` method
216+
217+
To make an async call with the `send_multi_request_sync` method, use the following code:
218+
219+
```python
220+
from iop import BusinessProcess
221+
from msg import MyMessage
222+
223+
224+
class MyMultiBP(BusinessProcess):
225+
226+
def on_message(self, request):
227+
msg_one = MyMessage(message="Message1")
228+
msg_two = MyMessage(message="Message2")
229+
230+
tuple_responses = self.send_multi_request_sync([("Python.MyMultiBO", msg_one),
231+
("Python.MyMultiBO", msg_two)])
232+
233+
self.log_info("All requests have been processed")
234+
for target,request,response,status in tuple_responses:
235+
self.log_info(f"Received response: {response.message}")
236+
```

0 commit comments

Comments
 (0)