from json import dumps from base58 import b58encode from httpx import AsyncClient from app.core._config import PROJECT_HOST from app.core._crypto.signer import Signer from app.core.logger import make_log async def send_status(service: str, status: str): make_log("send_status", f"Sending status (service={service}, status={status})", level='debug') try: message = { 'service': service, 'status': status, } message_bytes = dumps(message).encode() # Lazy import to avoid triggering _secrets before DB is ready from app.core._secrets import hot_seed signer = Signer(hot_seed) message_signature = signer.sign(message_bytes) async with AsyncClient() as client: res = await client.post( f"{PROJECT_HOST}/api/system.sendStatus", json={ 'message': b58encode(message_bytes).decode(), 'signature': message_signature, } ) if res.status_code != 200: make_log("send_status", f"Error (service={service}, status={status}, response={res.text})", level='error') except BaseException as e: make_log("send_status", f"Error: {e}", level='error')