Skip to content

Commit 3f4d703

Browse files
authored
Merge pull request #35 from remi-picard/fix-overloading-config
Fix overloading config and missing id in response
2 parents a327b2c + c3ee42e commit 3f4d703

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

RobotFrameworkService/routers/robotframework.py

+25-29
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212

1313
import multiprocessing as mp
1414

15-
from concurrent.futures import Future
16-
import threading
17-
1815
import asyncio
1916

2017
router = APIRouter(
@@ -27,16 +24,17 @@
2724
)
2825

2926

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)
3229
p.start()
3330
return p
3431

3532

36-
async def run_robot_and_wait(executor: Executor, func, args=[], kwargs={}):
33+
async def run_robot_and_wait(executor: Executor, func, args):
3734
# run robot concurrently and wait for it.
3835
loop = asyncio.get_event_loop()
3936
result: int = await loop.run_in_executor(executor, func, *args)
37+
id = args[0]
4038
if result == 0:
4139
result_page = "PASS"
4240
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):
6058
Run all task available.
6159
"""
6260
id = request.headers["request-id"]
61+
config = RFS_Config().cmd_args
6362
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]
6564
)
6665

6766
return response
@@ -73,7 +72,8 @@ async def run_all_async(request: Request):
7372
Starts all Robot tasks. Returns execution id and continures to run Robot tasks in background.
7473
"""
7574
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])
7777
return id
7878

7979

@@ -84,10 +84,11 @@ async def run_task(task, request: Request):
8484
"""
8585
id = request.headers["request-id"]
8686
variables = RequestHelper.parse_variables_from_query(request)
87+
config = RFS_Config().cmd_args
8788
response = await run_robot_and_wait(
8889
request.app.state.executor,
8990
func=_start_specific_robot_task,
90-
args=[id, task, variables],
91+
args=[id, task, variables, config],
9192
)
9293
return response
9394

@@ -99,9 +100,10 @@ async def run_task_async(task, request: Request):
99100
"""
100101
id = request.headers["request-id"]
101102
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(
103105
func=_start_specific_robot_task,
104-
kwargs={"id": id, "task": task, "variables": variables},
106+
args=[id, task, variables, config]
105107
)
106108
return id
107109

@@ -113,10 +115,11 @@ async def run_suite(suite, request: Request):
113115
"""
114116
id = request.headers["request-id"]
115117
variables = RequestHelper.parse_variables_from_query(request)
118+
config = RFS_Config().cmd_args
116119
response = await run_robot_and_wait(
117120
request.app.state.executor,
118121
func=_start_specific_robot_suite,
119-
args=[id, suite, variables],
122+
args=[id, suite, variables, config],
120123
)
121124
return response
122125

@@ -128,9 +131,10 @@ async def run_suite_async(suite, request: Request):
128131
"""
129132
id = request.headers["request-id"]
130133
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(
132136
func=_start_specific_robot_suite,
133-
kwargs={"id": id, "suite": suite, "variables": variables},
137+
args=[id, suite, variables, config]
134138
)
135139
return id
136140

@@ -142,10 +146,11 @@ async def start_robot_task_and_show_log(task: str, request: Request):
142146
"""
143147
id = request.headers["request-id"]
144148
variables = RequestHelper.parse_variables_from_query(request)
149+
config = RFS_Config().cmd_args
145150
await run_robot_and_wait(
146151
request.app.state.executor,
147152
func=_start_specific_robot_task,
148-
args=[id, task, variables],
153+
args=[id, task, variables, config],
149154
)
150155
return RedirectResponse(f"/logs/{id}/log.html")
151156

@@ -159,10 +164,11 @@ async def start_robot_task_and_show_report(task: str, request: Request):
159164
"""
160165
id = request.headers["request-id"]
161166
variables = RequestHelper.parse_variables_from_query(request)
167+
config = RFS_Config().cmd_args
162168
await run_robot_and_wait(
163169
request.app.state.executor,
164170
func=_start_specific_robot_task,
165-
args=[id, task, variables],
171+
args=[id, task, variables, config],
166172
)
167173
return RedirectResponse(f"/logs/{id}/report.html")
168174

@@ -224,10 +230,7 @@ async def show_execution_ids():
224230
return [log.stem for log in logs.iterdir() if is_execution_finished(log)]
225231

226232

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:
231234
if config.variablefiles is None:
232235
variablefiles = []
233236
else:
@@ -237,16 +240,12 @@ def _start_all_robot_tasks(id: str, variables: list = None) -> int:
237240
config.taskfolder,
238241
outputdir=f"logs/{id}",
239242
debugfile=config.debugfile,
240-
variable=variables,
241243
variablefile=variablefiles,
242244
consolewidth=120,
243245
)
244246

245247

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:
250249
if config.variablefiles is None:
251250
variablefiles = []
252251
else:
@@ -263,10 +262,7 @@ def _start_specific_robot_suite(id: str, suite: str, variables: list = None) ->
263262
)
264263

265264

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:
270266
if config.variablefiles is None:
271267
variablefiles = []
272268
else:

0 commit comments

Comments
 (0)