dev@locazia: fix sendStatus

This commit is contained in:
user 2024-03-03 14:33:23 +03:00
parent 64e86f360d
commit 8e37098057
5 changed files with 38 additions and 22 deletions

View File

@ -5,6 +5,7 @@ from datetime import datetime
import asyncio, sys import asyncio, sys
from aiogram import Bot from aiogram import Bot
import time
from app.api import app from app.api import app
from app.bot import dp from app.bot import dp
@ -78,6 +79,8 @@ if __name__ == '__main__':
app.run(host='0.0.0.0', port=SANIC_PORT) app.run(host='0.0.0.0', port=SANIC_PORT)
else: else:
time.sleep(3)
startup_fn = None startup_fn = None
if startup_target == 'indexator': if startup_target == 'indexator':
from app.core.background.indexator_service import main as target_fn from app.core.background.indexator_service import main as target_fn

View File

@ -10,7 +10,7 @@ from app.api.middleware import attach_user_to_request, close_db_session, close_r
app.register_middleware(attach_user_to_request, "request") app.register_middleware(attach_user_to_request, "request")
app.register_middleware(close_db_session, "response") app.register_middleware(close_db_session, "response")
from app.api.routes._index import s_index from app.api.routes._index import s_index, s_favicon
from app.api.routes._system import s_api_system, s_api_system_version, s_api_system_send_status from app.api.routes._system import s_api_system, s_api_system_version, s_api_system_send_status
from app.api.routes.auth import s_api_v1_auth_twa from app.api.routes.auth import s_api_v1_auth_twa
from app.api.routes.statics import s_api_tonconnect_manifest, s_api_platform_metadata from app.api.routes.statics import s_api_tonconnect_manifest, s_api_platform_metadata
@ -19,7 +19,8 @@ from app.api.routes.account import s_api_v1_account_get
from app.api.routes._blockchain import s_api_v1_blockchain_send_new_content_message, \ from app.api.routes._blockchain import s_api_v1_blockchain_send_new_content_message, \
s_api_v1_blockchain_send_purchase_content_message s_api_v1_blockchain_send_purchase_content_message
app.add_route(s_index, "/") app.add_route(s_index, "/", methods=["GET", "OPTIONS"])
app.add_route(s_favicon, "/favicon.ico", methods=["GET", "OPTIONS"])
app.add_route(s_api_system, "/api/node", methods=["GET", "OPTIONS"]) app.add_route(s_api_system, "/api/node", methods=["GET", "OPTIONS"])
app.add_route(s_api_system_version, "/api/system.version", methods=["GET", "OPTIONS"]) app.add_route(s_api_system_version, "/api/system.version", methods=["GET", "OPTIONS"])

View File

@ -2,5 +2,14 @@ from sanic import response
async def s_index(request): async def s_index(request):
return response.text("OK") return response.json({
'success': True,
'message': 'Welcome to the @MY API!'
})
async def s_favicon(request):
return response.redirect(
"https://git.projscale.dev/my-dev/assets/raw/commit/81de5356c6b1d6f01988d77e22c580114b32bcbd/images/logo.jpg"
)

View File

@ -3,6 +3,7 @@ from base58 import b58encode, b58decode
from app.core._secrets import hot_pubkey, service_wallet, hot_privkey from app.core._secrets import hot_pubkey, service_wallet, hot_privkey
from app.core._blockchain.ton.platform import platform from app.core._blockchain.ton.platform import platform
from datetime import datetime, timedelta from datetime import datetime, timedelta
from app.core.logger import make_log
from app.core._crypto.signer import Signer from app.core._crypto.signer import Signer
import subprocess import subprocess
import json import json
@ -51,7 +52,7 @@ async def s_api_system_send_status(request):
'status': message['status'], 'status': message['status'],
'timestamp': datetime.now(), 'timestamp': datetime.now(),
} }
make_log("Health", f"Service {message['service']} status: {message['status']}", level='info')
return response.json({'message': 'Status received'}) return response.json({'message': 'Status received'})

View File

@ -9,21 +9,23 @@ from app.core._crypto.signer import Signer
async def send_status(service: str, status: str): async def send_status(service: str, status: str):
message = { try:
'service': service, message = {
'status': status, 'service': service,
} 'status': status,
message_bytes = dumps(message).encode() }
signer = Signer(hot_seed) message_bytes = dumps(message).encode()
message_signature = signer.sign(message_bytes) signer = Signer(hot_seed)
async with AsyncClient() as client: message_signature = signer.sign(message_bytes)
res = await client.post( async with AsyncClient() as client:
f"{PROJECT_HOST}/api/system.sendStatus", res = await client.post(
json={ f"{PROJECT_HOST}/api/system.sendStatus",
'message': b58encode(message_bytes).decode(), json={
'signature': message_signature, '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') 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')