uploader-bot/app/core/_utils/send_status.py

30 lines
984 B
Python

from httpx import AsyncClient
from app.core._config import PROJECT_HOST
from app.core.logger import make_log
from app.core._secrets import hot_privkey, hot_seed
from tonsdk.utils import sign_message
from base58 import b58encode
from json import dumps
from app.core._crypto.signer import Signer
async def send_status(service: str, status: str):
message = {
'service': service,
'status': status,
}
message_bytes = dumps(message).encode()
signer = Signer(hot_privkey)
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')