Skip to content

Run

run()

Entrypoint of the application.

Source code in hestia/run.py
34
35
36
37
38
39
40
41
42
43
44
45
def run() -> None:
    """Entrypoint of the application."""
    set_multiproc_dir()
    uvicorn.run(
        "hestia.web.application:get_app",
        workers=settings.workers_count,
        host=settings.host,
        port=settings.port,
        reload=settings.reload,
        log_level=settings.log_level.value.lower(),
        factory=True,
    )

set_multiproc_dir()

Sets mutiproc_dir env variable.

This function cleans up the multiprocess directory and recreates it. This actions are required by prometheus-client to share metrics between processes.

After cleanup, it sets two variables. Uppercase and lowercase because different versions of the prometheus-client library depend on different environment variables, so I've decided to export all needed variables, to avoid undefined behaviour.

Source code in hestia/run.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def set_multiproc_dir() -> None:
    """
    Sets mutiproc_dir env variable.

    This function cleans up the multiprocess directory
    and recreates it. This actions are required by prometheus-client
    to share metrics between processes.

    After cleanup, it sets two variables.
    Uppercase and lowercase because different
    versions of the prometheus-client library
    depend on different environment variables,
    so I've decided to export all needed variables,
    to avoid undefined behaviour.
    """
    shutil.rmtree(settings.prometheus_dir, ignore_errors=True)
    os.makedirs(settings.prometheus_dir, exist_ok=True)
    os.environ["prometheus_multiproc_dir"] = str(
        settings.prometheus_dir.expanduser().absolute(),
    )
    os.environ["PROMETHEUS_MULTIPROC_DIR"] = str(
        settings.prometheus_dir.expanduser().absolute(),
    )