chore: Add Sentry to native Python runner (#19082)

This commit is contained in:
Iván Ovejero
2025-09-02 12:14:11 +02:00
committed by GitHub
parent 238fe84540
commit 4c4c0932d1
15 changed files with 356 additions and 152 deletions

View File

@@ -3,7 +3,9 @@ import logging
import sys
from typing import Optional
from src.env import parse_env_vars
from src.config.health_check_config import HealthCheckConfig
from src.config.sentry_config import SentryConfig
from src.config.task_runner_config import TaskRunnerConfig
from src.logs import setup_logging
from src.task_runner import TaskRunner
@@ -12,39 +14,56 @@ async def main():
setup_logging()
logger = logging.getLogger(__name__)
logger.info("Starting runner...")
sentry = None
sentry_config = SentryConfig.from_env()
if sentry_config.enabled:
from src.sentry import setup_sentry
sentry = setup_sentry(sentry_config)
try:
task_runner_opts, health_check_opts = parse_env_vars()
health_check_config = HealthCheckConfig.from_env()
except ValueError as e:
logger.error(str(e))
logger.error(f"Invalid health check configuration: {e}")
sys.exit(1)
task_runner = TaskRunner(task_runner_opts)
health_check_server: Optional["HealthCheckServer"] = None
if health_check_opts.enabled:
from src.health import HealthCheckServer
if health_check_config.enabled:
from src.health_check_server import HealthCheckServer
health_check_server = HealthCheckServer()
try:
await health_check_server.start(
health_check_opts.host, health_check_opts.port
)
await health_check_server.start(health_check_config)
except OSError as e:
logger.error(f"Failed to start health check server: {e}")
sys.exit(1)
try:
task_runner_config = TaskRunnerConfig.from_env()
except ValueError as e:
logger.error(str(e))
sys.exit(1)
task_runner = TaskRunner(task_runner_config)
logger.info("Starting runner...")
try:
await task_runner.start()
except (KeyboardInterrupt, asyncio.CancelledError):
logger.info("Shutting down runner...")
except Exception:
logger.error("Unexpected error", exc_info=True)
raise
finally:
await task_runner.stop()
if health_check_server:
await health_check_server.stop()
if sentry:
sentry.shutdown()
if __name__ == "__main__":
asyncio.run(main())