Пример #1
0
def on_starting(server: Arbiter):
    """Gunicorn pre-start tasks."""

    setup_lib_logging()

    python_version = platform.python_version()
    required = ".".join((str(v) for v in MIN_PYTHON_VERSION))
    log.info("Python {} detected ({} required)", python_version, required)

    async def runner():
        # Standard Library
        from asyncio import gather

        await gather(build_ui(), cache_config())

    check_redis_instance()
    aiorun(build_ui())
    cache_config()

    log.success(
        "Started hyperglass {v} on http://{h}:{p} with {w} workers",
        v=__version__,
        h=format_listen_address(params.listen_address),
        p=str(params.listen_port),
        w=server.app.cfg.settings["workers"].value,
    )
Пример #2
0
def on_exit(server: Arbiter):
    """Gunicorn shutdown tasks."""

    log.critical("Stopping hyperglass {}", __version__)

    async def runner():
        await clear_cache()

    aiorun(runner())
Пример #3
0
def build_ui(timeout: int) -> None:
    """Create a new UI build."""
    try:
        # Project
        from hyperglass.configuration import CONFIG_PATH, params, frontend_params
        from hyperglass.util.frontend import build_frontend
        from hyperglass.compat._asyncio import aiorun
    except ImportError as e:
        error("Error importing UI builder: {e}", e=e)

    status("Starting new UI build with a {t} second timeout...", t=timeout)

    if params.developer_mode:
        dev_mode = "development"
    else:
        dev_mode = "production"

    try:
        build_success = aiorun(
            build_frontend(
                dev_mode=params.developer_mode,
                dev_url=f"http://localhost:{str(params.listen_port)}/",
                prod_url="/api/",
                params=frontend_params,
                force=True,
                app_path=CONFIG_PATH,
            ))
        if build_success:
            success("Completed UI build in {m} mode", m=dev_mode)

    except Exception as e:
        error("Error building UI: {e}", e=e)

    return True
Пример #4
0
    def get_config(self):
        """Get picked config object from cache."""
        import pickle
        from hyperglass.compat._asyncio import aiorun

        pickled = aiorun(self.instance.get("HYPERGLASS_CONFIG"))
        return pickle.loads(pickled)
Пример #5
0
def build_ui():
    """Create a new UI build.

    Raises:
        ClickException: Raised on any errors.
    """
    try:
        from hyperglass.compat._asyncio import aiorun
        from hyperglass.util import build_frontend
        from hyperglass.configuration import params, frontend_params, CONFIG_PATH
    except ImportError as e:
        error("Error importing UI builder: {e}", e=e)

    status("Starting new UI build...")

    if params.developer_mode:
        dev_mode = "development"
    else:
        dev_mode = "production"

    try:
        build_success = aiorun(
            build_frontend(
                dev_mode=params.developer_mode,
                dev_url=f"http://localhost:{str(params.listen_port)}/",
                prod_url="/api/",
                params=frontend_params,
                force=True,
                app_path=CONFIG_PATH,
            ))
        if build_success:
            success("Completed UI build in {m} mode", m=dev_mode)

    except Exception as e:
        error("Error building UI: {e}", e=e)

    return True