browsertrix/backend/btrixcloud/main_op.py
Ilya Kreymer e13c3bfb48
move db migrations to initContainers: (#2449)
- should avoid gunicorn worker timeouts for long running migrations,
also fixes #2439
- add main_migrations as entrypoint to just run db migrations, using
existing init_ops() call
- first run 'migrations' container with same resources as 'app' and 'op'
- additional typing for initializing db
- cleanup unused code related to running only once, waiting for db to be ready
- fixes #2447
2025-03-03 13:13:15 -08:00

67 lines
1.4 KiB
Python

"""entrypoint module for operator"""
import os
import sys
from fastapi import FastAPI
from .operator import init_operator_api
from .ops import init_ops
from .utils import register_exit_handler
app_root = FastAPI()
# ============================================================================
# pylint: disable=too-many-function-args, duplicate-code
def main():
"""init operator"""
# pylint: disable=import-outside-toplevel
if not os.environ.get("KUBERNETES_SERVICE_HOST"):
print(
"Sorry, the Browsertrix Backend must be run inside a Kubernetes environment.\
Kubernetes not detected (KUBERNETES_SERVICE_HOST is not set), Exiting"
)
sys.exit(1)
(
org_ops,
crawl_config_ops,
_,
crawl_ops,
_,
page_ops,
coll_ops,
_,
storage_ops,
background_job_ops,
event_webhook_ops,
_,
_,
_,
_,
) = init_ops()
return init_operator_api(
app_root,
crawl_config_ops,
crawl_ops,
org_ops,
coll_ops,
storage_ops,
event_webhook_ops,
background_job_ops,
page_ops,
)
# ============================================================================
@app_root.on_event("startup")
async def startup():
"""init on startup"""
register_exit_handler()
settings = main()
await settings.async_init()