dev@locazia: many fixes

This commit is contained in:
user 2024-03-06 13:19:36 +03:00
parent dda25a71f4
commit cad723925c
3 changed files with 26 additions and 10 deletions

View File

@ -23,7 +23,7 @@ from app.api.routes.content import s_api_v1_content_list
app.add_route(s_index, "/", methods=["GET", "OPTIONS"])
app.add_route(s_favicon, "/favicon.ico", methods=["GET", "OPTIONS"])
app.add_route(s_api_v1_node, "/api/1/node", methods=["GET", "OPTIONS"])
app.add_route(s_api_v1_node, "/api/v1/node", methods=["GET", "OPTIONS"])
app.add_route(s_api_system_version, "/api/system.version", methods=["GET", "OPTIONS"])
app.add_route(s_api_system_send_status, "/api/system.sendStatus", methods=["POST", "OPTIONS"])

View File

@ -47,6 +47,7 @@ async def s_api_system_send_status(request):
return response.json({'error': 'Invalid signature'}, status=400)
message = json.loads(message)
assert message.get('service') in request.app.ctx.memory.known_states, "Unknown service"
request.app.ctx.memory.known_states[
message['service']
] = {

View File

@ -1,10 +1,11 @@
from tonsdk.boc import begin_cell
from app.core.logger import make_log
from app.core._config import MY_FUND_ADDRESS
from app.core._config import MY_FUND_ADDRESS, MY_PLATFORM_CONTRACT
from app.core.storage import db_session
from app.core._secrets import service_wallet
from app.core._blockchain.ton.toncenter import toncenter
from app.core._utils.send_status import send_status
from tonsdk.utils import Address
import asyncio
import os, sys
@ -37,7 +38,7 @@ async def main_fn():
)['message'].to_boc(False)
)
await asyncio.sleep(5)
return await main()
return await main_fn()
if os.getenv("TON_BEGIN_COMMAND_WITHDRAW"):
await toncenter.send_boc(
@ -53,17 +54,31 @@ async def main_fn():
make_log("TON", "Withdraw command sent", level="info")
await asyncio.sleep(10)
platform_state = await toncenter.get_account(MY_PLATFORM_CONTRACT)
if not platform_state.get('code'):
make_log("TON", "Platform contract is not deployed, shutdown service..", level="info")
await send_status("ton_daemon", "Platform contract is not deployed, not working")
while True:
await asyncio.sleep(100)
while True:
sw_seqno_value = await get_sw_seqno()
make_log("TON", f"Service running ({sw_seqno_value})", level="debug")
# with db_session() as session:
# for stored_content in session.query(StoredContent).filter(StoredContent.uploaded == False).all():
# pass
try:
sw_seqno_value = await get_sw_seqno()
make_log("TON", f"Service running ({sw_seqno_value})", level="debug")
await asyncio.sleep(5)
await send_status("ton", f"working (seqno={sw_seqno_value})")
# with db_session() as session:
# for stored_content in session.query(StoredContent).filter(StoredContent.uploaded == False).all():
# pass
await asyncio.sleep(5)
await send_status("ton_daemon", f"working (seqno={sw_seqno_value})")
except BaseException as e:
make_log("TON", f"Error: {e}", level="error")
await asyncio.sleep(3)
# if __name__ == '__main__':
# loop = asyncio.get_event_loop()
# loop.run_until_complete(main())