Skip to content

Commit

Permalink
Merge pull request #35 from remi-picard/fix-overloading-config
Browse files Browse the repository at this point in the history
Fix overloading config and missing id in response
  • Loading branch information
Noordsestern authored Feb 18, 2024
2 parents a327b2c + c3ee42e commit 3f4d703
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions RobotFrameworkService/routers/robotframework.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

import multiprocessing as mp

from concurrent.futures import Future
import threading

import asyncio

router = APIRouter(
Expand All @@ -27,16 +24,17 @@
)


async def run_robot_in_brackground(func, args=[], kwargs={}):
p = mp.Process(target=func, args=args, kwargs=kwargs)
async def run_robot_in_background(func, args):
p = mp.Process(target=func, args=args)
p.start()
return p


async def run_robot_and_wait(executor: Executor, func, args=[], kwargs={}):
async def run_robot_and_wait(executor: Executor, func, args):
# run robot concurrently and wait for it.
loop = asyncio.get_event_loop()
result: int = await loop.run_in_executor(executor, func, *args)
id = args[0]
if result == 0:
result_page = "PASS"
result_page += f'<p><a href="/logs/{id}/log.html">Go to log</a></p>'
Expand All @@ -60,8 +58,9 @@ async def run_all(request: Request):
Run all task available.
"""
id = request.headers["request-id"]
config = RFS_Config().cmd_args
response = await run_robot_and_wait(
request.app.state.executor, func=_start_all_robot_tasks, args=[id]
request.app.state.executor, func=_start_all_robot_tasks, args=[id, config]
)

return response
Expand All @@ -73,7 +72,8 @@ async def run_all_async(request: Request):
Starts all Robot tasks. Returns execution id and continures to run Robot tasks in background.
"""
id = request.headers["request-id"]
await run_robot_in_brackground(func=_start_all_robot_tasks, args=[id])
config = RFS_Config().cmd_args
await run_robot_in_background(func=_start_all_robot_tasks, args=[id, config])
return id


Expand All @@ -84,10 +84,11 @@ async def run_task(task, request: Request):
"""
id = request.headers["request-id"]
variables = RequestHelper.parse_variables_from_query(request)
config = RFS_Config().cmd_args
response = await run_robot_and_wait(
request.app.state.executor,
func=_start_specific_robot_task,
args=[id, task, variables],
args=[id, task, variables, config],
)
return response

Expand All @@ -99,9 +100,10 @@ async def run_task_async(task, request: Request):
"""
id = request.headers["request-id"]
variables = RequestHelper.parse_variables_from_query(request)
await run_robot_in_brackground(
config = RFS_Config().cmd_args
await run_robot_in_background(
func=_start_specific_robot_task,
kwargs={"id": id, "task": task, "variables": variables},
args=[id, task, variables, config]
)
return id

Expand All @@ -113,10 +115,11 @@ async def run_suite(suite, request: Request):
"""
id = request.headers["request-id"]
variables = RequestHelper.parse_variables_from_query(request)
config = RFS_Config().cmd_args
response = await run_robot_and_wait(
request.app.state.executor,
func=_start_specific_robot_suite,
args=[id, suite, variables],
args=[id, suite, variables, config],
)
return response

Expand All @@ -128,9 +131,10 @@ async def run_suite_async(suite, request: Request):
"""
id = request.headers["request-id"]
variables = RequestHelper.parse_variables_from_query(request)
await run_robot_in_brackground(
config = RFS_Config().cmd_args
await run_robot_in_background(
func=_start_specific_robot_suite,
kwargs={"id": id, "suite": suite, "variables": variables},
args=[id, suite, variables, config]
)
return id

Expand All @@ -142,10 +146,11 @@ async def start_robot_task_and_show_log(task: str, request: Request):
"""
id = request.headers["request-id"]
variables = RequestHelper.parse_variables_from_query(request)
config = RFS_Config().cmd_args
await run_robot_and_wait(
request.app.state.executor,
func=_start_specific_robot_task,
args=[id, task, variables],
args=[id, task, variables, config],
)
return RedirectResponse(f"/logs/{id}/log.html")

Expand All @@ -159,10 +164,11 @@ async def start_robot_task_and_show_report(task: str, request: Request):
"""
id = request.headers["request-id"]
variables = RequestHelper.parse_variables_from_query(request)
config = RFS_Config().cmd_args
await run_robot_and_wait(
request.app.state.executor,
func=_start_specific_robot_task,
args=[id, task, variables],
args=[id, task, variables, config],
)
return RedirectResponse(f"/logs/{id}/report.html")

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


def _start_all_robot_tasks(id: str, variables: list = None) -> int:
config = RFS_Config().cmd_args
if variables is None:
variables = []
def _start_all_robot_tasks(id: str, config) -> int:
if config.variablefiles is None:
variablefiles = []
else:
Expand All @@ -237,16 +240,12 @@ def _start_all_robot_tasks(id: str, variables: list = None) -> int:
config.taskfolder,
outputdir=f"logs/{id}",
debugfile=config.debugfile,
variable=variables,
variablefile=variablefiles,
consolewidth=120,
)


def _start_specific_robot_suite(id: str, suite: str, variables: list = None) -> int:
config = RFS_Config().cmd_args
if variables is None:
variables = []
def _start_specific_robot_suite(id: str, suite: str, variables: list, config) -> int:
if config.variablefiles is None:
variablefiles = []
else:
Expand All @@ -263,10 +262,7 @@ def _start_specific_robot_suite(id: str, suite: str, variables: list = None) ->
)


def _start_specific_robot_task(id: str, task: str, variables: list = None) -> int:
config = RFS_Config().cmd_args
if variables is None:
variables = []
def _start_specific_robot_task(id: str, task: str, variables: list, config) -> int:
if config.variablefiles is None:
variablefiles = []
else:
Expand Down

0 comments on commit 3f4d703

Please sign in to comment.