def _send_schedule_message( message_contents: dict, message_type: MessageBase, with_authentication: bool = False, authenticated: bool = False ): message_contents["service_version"] = SERVICE_VERSION message_contents["component_name"] = COMPONENT_NAME message = message_type.MessageContents(**message_contents) producer.publish_to_topic(p, message_type(), message) if "job_id" in message_contents: if with_authentication: return ( { "analysis_id": message_contents["job_id"], "cached": False, "authenticated": authenticated, "parameters": message_contents, }, 202, ) return ( { "analysis_id": message_contents["job_id"], "parameters": message_contents, "cached": False, }, 202, ) raise ValueError(f"job_id was not set for message sent to {message_type().topic_name}")
from prometheus_client import generate_latest import asyncio import logging import faust import os import ssl from urllib.parse import urlparse from aiohttp import web init_logging() _LOGGER = logging.getLogger(__name__) _LOGGER.info("Thoth Package Update consumer v%s", __service_version__) app = MessageBase().app hash_mismatch_topic = HashMismatchMessage().topic missing_package_topic = MissingPackageMessage().topic missing_version_topic = MissingVersionMessage().topic @app.page("/metrics") async def get_metrics(self, request): """Serve the metrics from the consumer registry.""" return web.Response(text=generate_latest().decode("utf-8")) @app.page("/_health") async def get_health(self, request): """Serve a readiness/liveness probe endpoint."""
import logging import faust import os import ssl from functools import wraps from aiohttp.client_exceptions import ClientResponseError from typing import Dict, Any, Tuple, Callable from package_update import __service_version__ as __package_update_version__ init_logging() _LOGGER = logging.getLogger(__name__) _LOGGER.info("Thoth package update producer v%s", __package_update_version__) app = MessageBase().app SEMAPHORE_LIMIT = int(os.getenv("THOTH_PACKAGE_UPDATE_SEMAPHORE_LIMIT", 1000)) async_sem = asyncio.Semaphore(SEMAPHORE_LIMIT) COMPONENT_NAME = "package-update-job" def redirect_exception_message(func): """Redirect a messages exception to be logged instead of halting execution.""" async def inner_function(*args, **kwargs): try: await func(*args, **kwargs) except Exception(e): _LOGGER.warning(e) return inner_function