"""Gunicorn configuration for the independent DataOps Runner."""

import os


bind = (
    f"{os.environ.get('RUNNER_LISTEN_HOST', '0.0.0.0')}:"
    f"{os.environ.get('RUNNER_LISTEN_PORT', '5600')}"
)
workers = int(os.environ.get("RUNNER_WORKERS", "2"))
threads = int(os.environ.get("RUNNER_THREADS", "2"))
timeout = int(os.environ.get("RUNNER_TIMEOUT", "120"))
capture_output = True
enable_stdio_inheritance = True
loglevel = os.environ.get("RUNNER_LOG_LEVEL", "info")


def worker_exit(server, worker):
    del server, worker
    from app.runner.wsgi import application

    runtime = application.extensions.get("dataops_runner_runtime")
    if runtime is not None:
        runtime.close()
