12
12
13
13
import multiprocessing as mp
14
14
15
- from concurrent .futures import Future
16
- import threading
17
-
18
15
import asyncio
19
16
20
17
router = APIRouter (
27
24
)
28
25
29
26
30
- async def run_robot_in_brackground (func , args = [], kwargs = {} ):
31
- p = mp .Process (target = func , args = args , kwargs = kwargs )
27
+ async def run_robot_in_background (func , args ):
28
+ p = mp .Process (target = func , args = args )
32
29
p .start ()
33
30
return p
34
31
35
32
36
- async def run_robot_and_wait (executor : Executor , func , args = [], kwargs = {} ):
33
+ async def run_robot_and_wait (executor : Executor , func , args ):
37
34
# run robot concurrently and wait for it.
38
35
loop = asyncio .get_event_loop ()
39
36
result : int = await loop .run_in_executor (executor , func , * args )
37
+ id = args [0 ]
40
38
if result == 0 :
41
39
result_page = "PASS"
42
40
result_page += f'<p><a href="/logs/{ id } /log.html">Go to log</a></p>'
@@ -60,8 +58,9 @@ async def run_all(request: Request):
60
58
Run all task available.
61
59
"""
62
60
id = request .headers ["request-id" ]
61
+ config = RFS_Config ().cmd_args
63
62
response = await run_robot_and_wait (
64
- request .app .state .executor , func = _start_all_robot_tasks , args = [id ]
63
+ request .app .state .executor , func = _start_all_robot_tasks , args = [id , config ]
65
64
)
66
65
67
66
return response
@@ -73,7 +72,8 @@ async def run_all_async(request: Request):
73
72
Starts all Robot tasks. Returns execution id and continures to run Robot tasks in background.
74
73
"""
75
74
id = request .headers ["request-id" ]
76
- await run_robot_in_brackground (func = _start_all_robot_tasks , args = [id ])
75
+ config = RFS_Config ().cmd_args
76
+ await run_robot_in_background (func = _start_all_robot_tasks , args = [id , config ])
77
77
return id
78
78
79
79
@@ -84,10 +84,11 @@ async def run_task(task, request: Request):
84
84
"""
85
85
id = request .headers ["request-id" ]
86
86
variables = RequestHelper .parse_variables_from_query (request )
87
+ config = RFS_Config ().cmd_args
87
88
response = await run_robot_and_wait (
88
89
request .app .state .executor ,
89
90
func = _start_specific_robot_task ,
90
- args = [id , task , variables ],
91
+ args = [id , task , variables , config ],
91
92
)
92
93
return response
93
94
@@ -99,9 +100,10 @@ async def run_task_async(task, request: Request):
99
100
"""
100
101
id = request .headers ["request-id" ]
101
102
variables = RequestHelper .parse_variables_from_query (request )
102
- await run_robot_in_brackground (
103
+ config = RFS_Config ().cmd_args
104
+ await run_robot_in_background (
103
105
func = _start_specific_robot_task ,
104
- kwargs = { "id" : id , " task" : task , " variables" : variables },
106
+ args = [ id , task , variables , config ]
105
107
)
106
108
return id
107
109
@@ -113,10 +115,11 @@ async def run_suite(suite, request: Request):
113
115
"""
114
116
id = request .headers ["request-id" ]
115
117
variables = RequestHelper .parse_variables_from_query (request )
118
+ config = RFS_Config ().cmd_args
116
119
response = await run_robot_and_wait (
117
120
request .app .state .executor ,
118
121
func = _start_specific_robot_suite ,
119
- args = [id , suite , variables ],
122
+ args = [id , suite , variables , config ],
120
123
)
121
124
return response
122
125
@@ -128,9 +131,10 @@ async def run_suite_async(suite, request: Request):
128
131
"""
129
132
id = request .headers ["request-id" ]
130
133
variables = RequestHelper .parse_variables_from_query (request )
131
- await run_robot_in_brackground (
134
+ config = RFS_Config ().cmd_args
135
+ await run_robot_in_background (
132
136
func = _start_specific_robot_suite ,
133
- kwargs = { "id" : id , " suite" : suite , " variables" : variables },
137
+ args = [ id , suite , variables , config ]
134
138
)
135
139
return id
136
140
@@ -142,10 +146,11 @@ async def start_robot_task_and_show_log(task: str, request: Request):
142
146
"""
143
147
id = request .headers ["request-id" ]
144
148
variables = RequestHelper .parse_variables_from_query (request )
149
+ config = RFS_Config ().cmd_args
145
150
await run_robot_and_wait (
146
151
request .app .state .executor ,
147
152
func = _start_specific_robot_task ,
148
- args = [id , task , variables ],
153
+ args = [id , task , variables , config ],
149
154
)
150
155
return RedirectResponse (f"/logs/{ id } /log.html" )
151
156
@@ -159,10 +164,11 @@ async def start_robot_task_and_show_report(task: str, request: Request):
159
164
"""
160
165
id = request .headers ["request-id" ]
161
166
variables = RequestHelper .parse_variables_from_query (request )
167
+ config = RFS_Config ().cmd_args
162
168
await run_robot_and_wait (
163
169
request .app .state .executor ,
164
170
func = _start_specific_robot_task ,
165
- args = [id , task , variables ],
171
+ args = [id , task , variables , config ],
166
172
)
167
173
return RedirectResponse (f"/logs/{ id } /report.html" )
168
174
@@ -224,10 +230,7 @@ async def show_execution_ids():
224
230
return [log .stem for log in logs .iterdir () if is_execution_finished (log )]
225
231
226
232
227
- def _start_all_robot_tasks (id : str , variables : list = None ) -> int :
228
- config = RFS_Config ().cmd_args
229
- if variables is None :
230
- variables = []
233
+ def _start_all_robot_tasks (id : str , config ) -> int :
231
234
if config .variablefiles is None :
232
235
variablefiles = []
233
236
else :
@@ -237,16 +240,12 @@ def _start_all_robot_tasks(id: str, variables: list = None) -> int:
237
240
config .taskfolder ,
238
241
outputdir = f"logs/{ id } " ,
239
242
debugfile = config .debugfile ,
240
- variable = variables ,
241
243
variablefile = variablefiles ,
242
244
consolewidth = 120 ,
243
245
)
244
246
245
247
246
- def _start_specific_robot_suite (id : str , suite : str , variables : list = None ) -> int :
247
- config = RFS_Config ().cmd_args
248
- if variables is None :
249
- variables = []
248
+ def _start_specific_robot_suite (id : str , suite : str , variables : list , config ) -> int :
250
249
if config .variablefiles is None :
251
250
variablefiles = []
252
251
else :
@@ -263,10 +262,7 @@ def _start_specific_robot_suite(id: str, suite: str, variables: list = None) ->
263
262
)
264
263
265
264
266
- def _start_specific_robot_task (id : str , task : str , variables : list = None ) -> int :
267
- config = RFS_Config ().cmd_args
268
- if variables is None :
269
- variables = []
265
+ def _start_specific_robot_task (id : str , task : str , variables : list , config ) -> int :
270
266
if config .variablefiles is None :
271
267
variablefiles = []
272
268
else :
0 commit comments