Skip to content

Commit 86e35dc

Browse files
author
Prabhakar Kumar
committed
Update to v0.2.9 with bug fixes and change to write to server URL to mwi_proxy.lock
1. background tasks are manually instead of using app.on_startup to prevent race condition on setting mwi_server_url into mwi_proxy.lock in the presence of proxy_config_app.json 2. Added endpoint to accept base_url without trailing "/" character 3. Bug fix which includes base_url with site.name for mwi_server_url
1 parent 4c57843 commit 86e35dc

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

matlab_proxy/app.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ async def root_redirect(request):
257257
Returns:
258258
HTTPResponse: HTTPResponse Object containing the index.html file.
259259
"""
260-
return aiohttp.web.HTTPFound("./index.html")
260+
base_url = request.app["settings"]["base_url"]
261+
return aiohttp.web.HTTPFound(f"{base_url}/index.html")
261262

262263

263264
async def static_get(req):
@@ -540,7 +541,7 @@ def configure_and_start(app):
540541

541542
# Update the site origin in settings.
542543
# The origin will be used for communicating with the Embedded connector.
543-
app["settings"]["mwi_server_url"] = site.name
544+
app["settings"]["mwi_server_url"] = site.name + app["settings"]["base_url"]
544545

545546
loop.run_until_complete(site.start())
546547

@@ -552,10 +553,14 @@ def configure_and_start(app):
552553
logger.info(
553554
util.prettify(
554555
boundary_filler="=",
555-
text_arr=[f"MATLAB can be accessed at:", site.name],
556+
text_arr=[f"MATLAB can be accessed at:", app["settings"]["mwi_server_url"]],
556557
)
557558
)
558559

560+
# Startup tasks are being done here as app.on_startup leads
561+
# to a race condition for mwi_server_url information which is
562+
# extracted from the site info.
563+
loop.run_until_complete(start_background_tasks(app))
559564
return app
560565

561566

@@ -596,9 +601,9 @@ def create_app(config_name=matlab_proxy.get_default_config_name()):
596601
"DELETE", f"{base_url}/terminate_integration", termination_integration_delete
597602
)
598603
app.router.add_route("*", f"{base_url}/", root_redirect)
604+
app.router.add_route("*", f"{base_url}", root_redirect)
599605
app.router.add_route("*", f"{base_url}/{{proxyPath:.*}}", matlab_view)
600606

601-
app.on_startup.append(start_background_tasks)
602607
app.on_cleanup.append(cleanup_background_tasks)
603608

604609
return app

matlab_proxy/app_state.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,9 @@ def prepare_lock_files_for_MATLAB_launch(self):
406406
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
407407
s.bind(("", port))
408408

409+
# Use the app_port number to identify the server as that is user visible
409410
matlab_ready_file_dir = self.settings["mwi_logs_root_dir"] / str(
410-
port
411+
self.settings["app_port"]
411412
)
412413

413414
mwi_proxy_lock_file = (
@@ -432,7 +433,8 @@ def prepare_lock_files_for_MATLAB_launch(self):
432433

433434
# Creating the mwi_proxy.lock file to indicate to any other matlab-proxy processes
434435
# that this self.matlab_port number is taken up by this process.
435-
mwi_proxy_lock_file.touch()
436+
with open(mwi_proxy_lock_file, "w") as lock_file:
437+
lock_file.write(self.settings["mwi_server_url"] + "/")
436438

437439
# Update member variables of AppState class
438440

matlab_proxy/matlab/startup.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@
3333
end
3434
matlab_settings.matlab.addons.explorer.isExplorerSupported.TemporaryValue = false;
3535

36-
clear matlab_settings
36+
clear matlab_settings
37+
clc

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def run(self):
5151

5252
setuptools.setup(
5353
name="matlab-proxy",
54-
version="0.2.8",
54+
version="0.2.9",
5555
url=config["doc_url"],
5656
author="The MathWorks, Inc.",
5757
author_email="[email protected]",

tests/test_app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ def test_create_app():
2222
# Verify router is configured with some routes
2323
assert test_server.router._resources is not None
2424

25-
# Verify app server has startup and cleanup tasks
26-
# By default there is 1 start up and clean up task
27-
assert len(test_server._on_startup) > 1
25+
# Verify app server has a cleanup task
26+
# By default there is 1 for clean up task
2827
assert len(test_server.on_cleanup) > 1
2928

3029

0 commit comments

Comments
 (0)