import os
import sys
from logging import basicConfig, getLogger
from multiprocessing import cpu_count
from .service import serve, ServiceArguments

UNIX_SOCKET_PATH = os.environ.get("COALESCE_RENDERER_UNIX_SOCKET_PATH")
RENDERER_POOL_SIZE = int(os.environ.get("COALESCE_MAX_RENDERER_CONCURRENCY", max([cpu_count() - 2, 2])))

if __name__ == "__main__":
    basicConfig()
    if not UNIX_SOCKET_PATH:
        getLogger("renderer").error("No unix socket path provided, service cannot run")
        sys.exit(1)
    args = ServiceArguments(RENDERER_POOL_SIZE, UNIX_SOCKET_PATH, None)
    serve(args)
