"""Entry point: `python -m app` serves the API, `python -m app prefetch` warms the model volume.""" from __future__ import annotations import logging import sys import uvicorn from .config import ConfigError, Settings from .main import create_app from .models import Registry def main(argv: list[str]) -> int: logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s %(message)s") try: settings = Settings.from_env() except ConfigError as error: print(f"media-worker: {error}", file=sys.stderr) return 2 if argv[1:] == ["prefetch"]: Registry(settings).prefetch() return 0 if argv[1:]: print("usage: python -m app [prefetch]", file=sys.stderr) return 2 uvicorn.run( create_app(settings), host=settings.host, port=settings.port, log_level="info", access_log=False ) return 0 if __name__ == "__main__": sys.exit(main(sys.argv))