dev@locazia: make indexator
This commit is contained in:
parent
cad723925c
commit
2003688c94
|
|
@ -1,15 +1,42 @@
|
||||||
from app.core._utils.send_status import send_status
|
from app.core._utils.send_status import send_status
|
||||||
|
from app.core._config import MY_PLATFORM_CONTRACT
|
||||||
|
from app.core._blockchain.ton.toncenter import toncenter
|
||||||
|
from app.core.models.node_storage import StoredContent
|
||||||
|
from app.core.storage import db_session
|
||||||
from app.core.logger import make_log
|
from app.core.logger import make_log
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
|
async def indexator_loop(platform_found: bool, seqno: int) -> [bool, int]:
|
||||||
|
if not platform_found:
|
||||||
|
platform_state = await toncenter.get_account(MY_PLATFORM_CONTRACT)
|
||||||
|
if not platform_state.get('code'):
|
||||||
|
make_log("TON", "Platform contract is not deployed, skipping loop", level="info")
|
||||||
|
await send_status("indexator", "not working: platform is not deployed")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
platform_found = True
|
||||||
|
|
||||||
|
make_log("Indexator", "Service running", level="debug")
|
||||||
|
with db_session() as session:
|
||||||
|
last_known_index = session.query(StoredContent).order_by(StoredContent.onchain_index.desc()).first()
|
||||||
|
last_known_index = last_known_index.onchain_index if last_known_index >= 0 else 0
|
||||||
|
make_log("Indexator", f"Last known index: {last_known_index}", level="debug")
|
||||||
|
|
||||||
|
await send_status("indexator", f"working (seqno={seqno})")
|
||||||
|
return platform_found, seqno
|
||||||
|
|
||||||
async def main_fn():
|
async def main_fn():
|
||||||
make_log("Indexator", "Service started", level="info")
|
make_log("Indexator", "Service started", level="info")
|
||||||
|
platform_found = False
|
||||||
seqno = 0
|
seqno = 0
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
|
platform_found, seqno = await indexator_loop(platform_found, seqno)
|
||||||
|
except BaseException as e:
|
||||||
|
make_log("Indexator", f"Error: {e}", level="error")
|
||||||
|
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
await send_status("indexator", f"working (seqno={seqno})")
|
|
||||||
seqno += 1
|
seqno += 1
|
||||||
|
|
||||||
# if __name__ == '__main__':
|
# if __name__ == '__main__':
|
||||||
|
|
|
||||||
|
|
@ -54,21 +54,11 @@ async def main_fn():
|
||||||
make_log("TON", "Withdraw command sent", level="info")
|
make_log("TON", "Withdraw command sent", level="info")
|
||||||
await asyncio.sleep(10)
|
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:
|
while True:
|
||||||
try:
|
try:
|
||||||
sw_seqno_value = await get_sw_seqno()
|
sw_seqno_value = await get_sw_seqno()
|
||||||
make_log("TON", f"Service running ({sw_seqno_value})", level="debug")
|
make_log("TON", f"Service running ({sw_seqno_value})", level="debug")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# with db_session() as session:
|
# with db_session() as session:
|
||||||
# for stored_content in session.query(StoredContent).filter(StoredContent.uploaded == False).all():
|
# for stored_content in session.query(StoredContent).filter(StoredContent.uploaded == False).all():
|
||||||
# pass
|
# pass
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ async def main_fn():
|
||||||
make_log("Uploader", "Service running", level="debug")
|
make_log("Uploader", "Service running", level="debug")
|
||||||
await uploader_loop()
|
await uploader_loop()
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
await send_status("uploader", f"working (seqno={seqno})")
|
await send_status("uploader_daemon", f"working (seqno={seqno})")
|
||||||
seqno += 1
|
seqno += 1
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
make_log("Uploader", f"Error: {e}", level="error")
|
make_log("Uploader", f"Error: {e}", level="error")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue