Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overloading config and missing id in response #35

Merged
merged 2 commits into from
Feb 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Noordsestern marked this conversation as resolved.
Show resolved Hide resolved

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]
Noordsestern marked this conversation as resolved.
Show resolved Hide resolved
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},
Noordsestern marked this conversation as resolved.
Show resolved Hide resolved
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, marked for later tracability: Why do we make variables a mandatory argument?

Copy link
Author

@remi-picard remi-picard Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This time, variables is always passed with _start_specific_robot_suite method. I think it should be mandatory.

Examples :

@router.get("/run/suite/{suite}", tags=["execution"])
async def run_suite(suite, request: Request):
    #...
    variables = RequestHelper.parse_variables_from_query(request)
    #...
    response = await run_robot_and_wait(
        request.app.state.executor,
        func=_start_specific_robot_suite,
        args=[id, suite, variables, config],
    )

We can remove the following 2 lines :

    if variables is None:
        variables = []

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have pushed the changes

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, marked for later tracability: Why do we make variables a mandatory argument?

Copy link
Author

@remi-picard remi-picard Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variables is always passed with _start_specific_robot_task method. I think it should be mandatory.

We can remove the following 2 lines :

    if variables is None:
        variables = []

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have pushed the changes

if config.variablefiles is None:
variablefiles = []
else:
Expand Down
Loading