Skip to content

dashboard

Dashboard #

Source code in cogip/tools/dashboard_beacon/dashboard.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Dashboard:
    _exiting: bool = False  # True if Uvicorn server was ask to shutdown
    _original_uvicorn_exit_handler = Server.handle_exit  # Backup of original exit handler to overload it

    def __init__(self):
        """
        Class constructor.

        Create FastAPI application.
        """
        self.app = FastAPI(title="COGIP Beacon Dashboard", debug=False)

        # Overload default Uvicorn exit handler
        Server.handle_exit = self.handle_exit

        # Mount static files
        current_dir = Path(__file__).parent
        self.app.mount("/static", StaticFiles(directory=current_dir / "static"), name="static")

        # Create HTML templates
        self.templates = Jinja2Templates(directory=current_dir / "templates")

        # Register routes
        self.app.include_router(routes.BeaconRouter(self.templates), prefix="")

    @staticmethod
    def handle_exit(*args, **kwargs):
        """Overload function for Uvicorn handle_exit"""
        Dashboard._exiting = True
        Dashboard._original_uvicorn_exit_handler(*args, **kwargs)

__init__() #

Class constructor.

Create FastAPI application.

Source code in cogip/tools/dashboard_beacon/dashboard.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def __init__(self):
    """
    Class constructor.

    Create FastAPI application.
    """
    self.app = FastAPI(title="COGIP Beacon Dashboard", debug=False)

    # Overload default Uvicorn exit handler
    Server.handle_exit = self.handle_exit

    # Mount static files
    current_dir = Path(__file__).parent
    self.app.mount("/static", StaticFiles(directory=current_dir / "static"), name="static")

    # Create HTML templates
    self.templates = Jinja2Templates(directory=current_dir / "templates")

    # Register routes
    self.app.include_router(routes.BeaconRouter(self.templates), prefix="")

handle_exit(*args, **kwargs) staticmethod #

Overload function for Uvicorn handle_exit

Source code in cogip/tools/dashboard_beacon/dashboard.py
36
37
38
39
40
@staticmethod
def handle_exit(*args, **kwargs):
    """Overload function for Uvicorn handle_exit"""
    Dashboard._exiting = True
    Dashboard._original_uvicorn_exit_handler(*args, **kwargs)