diff --git a/app/app.py b/app/app.py index a27e4a5..6f26813 100644 --- a/app/app.py +++ b/app/app.py @@ -2,6 +2,8 @@ import dash # type: ignore from dash import Dash, dcc, html # type: ignore +from .core_api import create_all + app = Dash(__package__, use_pages=True, update_title=None) app.layout = html.Div( @@ -25,5 +27,9 @@ server = app.server +# Create the OVE Sections +create_all() + + if __name__ == "__main__": app.run_server(debug=True) diff --git a/app/core_api.py b/app/core_api.py index 5998f9f..f73d503 100644 --- a/app/core_api.py +++ b/app/core_api.py @@ -1,14 +1,17 @@ """Interacts with the OVE Core API.""" import json +import logging +import os +import time import requests """ Constants for API URLs. """ -APP_URL = "http://146.179.34.13:8080/app/html" -API_URL = "http://liionsden.rcs.ic.ac.uk:8080" -PLOT_URL = "http://liionsden.rcs.ic.ac.uk:8050" +APP_URL = os.environ.get("APP_URL", "http://146.179.34.13:8080/app/html") +API_URL = os.environ.get("API_URL", "http://liionsden.rcs.ic.ac.uk:8080") +PLOT_URL = os.environ.get("PLOT_URL", "http://liionsden.rcs.ic.ac.uk:8050") """ Initial config for sections. @@ -89,11 +92,18 @@ ] +def wait_for_ove() -> None: + """Function to wait for the OVE Core API to be available after startup.""" + while requests.get(API_URL).status_code != 200: + time.sleep(5) + + def create_all() -> None: """Function for creating all initial sections.""" + wait_for_ove() for section in INIT_SECTIONS: response = requests.post(f"{API_URL}/section", json=section) - print(response.text) + logging.info(response.text) def move_section(id_num: int, space: str) -> None: diff --git a/configure.py b/configure.py index cb54948..3d66d75 100755 --- a/configure.py +++ b/configure.py @@ -45,6 +45,7 @@ def generate_docker_compose(template_file: str, ip: str, develop: bool = False) "OVE_HOST": f"{ip}:8080", # TODO: Point to the on-prem openvidu (keep as port 4443) "OPENVIDU_HOST": "https://146.179.34.13:4443", + "PLOT_URL": f"{ip}:8050", } # Read the template file @@ -68,6 +69,11 @@ def generate_docker_compose(template_file: str, ip: str, develop: bool = False) docker_compose["services"]["dash"] = { "ports": ["8050:8050"], "volumes": ["./app:/app"], + "environment": { + "APP_URL": f"http://{lines_to_replace['OVE_HOST']}/app/html", + "API_URL": f"http://{lines_to_replace['OVE_HOST']}", + "PLOT_URL": f"http://{lines_to_replace['PLOT_URL']}", + }, } if develop: docker_compose["services"]["dash"]["build"] = "."