from laborchestrator.old_dash_app import SMDashApp
from laborchestrator.orchestrator_implementation import Orchestrator
import time
from os import path
from laborchestrator.logging_manager import StandardLogger as Logger


def start_up():
    # create orchestrator
    orchestrator = Orchestrator()
    # try to find a running scheduler server and set its lab configuration to the default
    try:
        from labscheduler.sila_server.generated.client import Client as SchedulerClient
        scheduler = SchedulerClient.discover(insecure=True, timeout=5)
        # get the absolute filepath
        here = path.abspath(__file__)
        config_file = path.join(here, '..', "tests", "test_data", "sila_server_config_changed.yml")
        scheduler.LabConfigurationController.LoadJobShopFromFile(config_file)
        Logger.info("Configured the lab of the scheduling service")
    except:
        Logger.warning("Could not find a running scheduler server. You will have to configure the lab manually.")

    # start the dash app
    dash_app = SMDashApp(orchestrator)
    dash_app.run()

    while True:
        time.sleep(1)


if __name__== "__main__":
    start_up()
