try fix licenses

This commit is contained in:
user 2025-03-14 10:54:57 +03:00
parent 7d962d463b
commit 66da3541e7
3 changed files with 14 additions and 10 deletions

View File

@ -3,7 +3,7 @@ from base64 import b64decode
from datetime import datetime, timedelta from datetime import datetime, timedelta
from base58 import b58encode from base58 import b58encode
from sqlalchemy import and_ from sqlalchemy import and_, or_
from tonsdk.boc import Cell from tonsdk.boc import Cell
from tonsdk.utils import Address from tonsdk.utils import Address
@ -74,12 +74,14 @@ async def license_index_loop(memory, platform_found: bool, seqno: int) -> [bool,
# Проверка кошельков пользователей на появление новых NFT, добавление их в базу как неопознанные # Проверка кошельков пользователей на появление новых NFT, добавление их в базу как неопознанные
for user in session.query(User).filter( for user in session.query(User).filter(
User.last_use > datetime.now() - timedelta(minutes=10) User.last_use > datetime.now() - timedelta(hours=4)
).all(): ).order_by(User.updated.asc()).all():
if not user.wallet_address(session): user_wallet_address = user.wallet_address(session)
if not user_wallet_address:
make_log("LicenseIndex", f"User {user.id} has no wallet address", level="info") make_log("LicenseIndex", f"User {user.id} has no wallet address", level="info")
continue continue
make_log("LicenseIndex", f"User {user.id} has wallet address {user_wallet_address}", level="info")
last_updated_licenses = user.meta.get('last_updated_licenses') last_updated_licenses = user.meta.get('last_updated_licenses')
must_skip = last_updated_licenses and (datetime.now() - datetime.fromisoformat(last_updated_licenses)) < timedelta(minutes=1) must_skip = last_updated_licenses and (datetime.now() - datetime.fromisoformat(last_updated_licenses)) < timedelta(minutes=1)
make_log("LicenseIndex", f"User: {user.id}, last_updated_licenses: {last_updated_licenses}, must_skip: {must_skip}", level="info") make_log("LicenseIndex", f"User: {user.id}, last_updated_licenses: {last_updated_licenses}, must_skip: {must_skip}", level="info")
@ -99,7 +101,7 @@ async def license_index_loop(memory, platform_found: bool, seqno: int) -> [bool,
UserContent.type.startswith('nft/'), UserContent.type.startswith('nft/'),
UserContent.updated < (datetime.now() - timedelta(minutes=60)), UserContent.updated < (datetime.now() - timedelta(minutes=60)),
) )
).first() ).order_by(UserContent.updated.asc()).first()
if process_content: if process_content:
make_log("LicenseIndex", f"Syncing content with blockchain: {process_content.id}", level="info") make_log("LicenseIndex", f"Syncing content with blockchain: {process_content.id}", level="info")
try: try:

View File

@ -157,7 +157,7 @@ async def main_fn(memory):
in_msg_blockchain_task.status = 'done' in_msg_blockchain_task.status = 'done'
in_msg_blockchain_task.transaction_hash = transaction_hash in_msg_blockchain_task.transaction_hash = transaction_hash
in_msg_blockchain_task.transaction_lt = transaction_lt in_msg_blockchain_task.transaction_lt = transaction_lt
await session.commit() session.commit()
for blockchain_message in [transaction['in_msg']]: for blockchain_message in [transaction['in_msg']]:
try: try:
@ -210,7 +210,7 @@ async def main_fn(memory):
# or sum([int("terminating vm with exit code 36" in e) for e in errors_list]) > 0: # or sum([int("terminating vm with exit code 36" in e) for e in errors_list]) > 0:
make_log("TON_Daemon", f"Task {blockchain_task.id} done", level="DEBUG") make_log("TON_Daemon", f"Task {blockchain_task.id} done", level="DEBUG")
blockchain_task.status = 'done' blockchain_task.status = 'done'
await session.commit() session.commit()
continue continue
await asyncio.sleep(0.5) await asyncio.sleep(0.5)
@ -266,7 +266,7 @@ async def main_fn(memory):
'sign_created': sign_created, 'sign_created': sign_created,
'signed_message': query_boc.hex(), 'signed_message': query_boc.hex(),
} }
await session.commit() session.commit()
make_log("TON", f"Created signed message for task {blockchain_task.id}" + '\n' + traceback.format_exc(), level="info") make_log("TON", f"Created signed message for task {blockchain_task.id}" + '\n' + traceback.format_exc(), level="info")
except BaseException as e: except BaseException as e:
make_log("TON", f"Error processing task {blockchain_task.id}: {e}" + '\n' + traceback.format_exc(), level="error") make_log("TON", f"Error processing task {blockchain_task.id}: {e}" + '\n' + traceback.format_exc(), level="error")

View File

@ -1,3 +1,4 @@
from datetime import datetime
from sqlalchemy import Column, Integer, String, BigInteger, DateTime, JSON from sqlalchemy import Column, Integer, String, BigInteger, DateTime, JSON
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
@ -19,8 +20,9 @@ class User(AlchemyBase, DisplayMixin, TranslationCore, AuthenticationMixin_V1, W
lang_code = Column(String(8), nullable=False, default="en") lang_code = Column(String(8), nullable=False, default="en")
meta = Column(JSON, nullable=False, default={}) meta = Column(JSON, nullable=False, default={})
last_use = Column(DateTime, nullable=False, default=0) last_use = Column(DateTime, nullable=False, default=datetime.utcnow)
created = Column(DateTime, nullable=False, default=0) updated = Column(DateTime, nullable=False, default=datetime.utcnow)
created = Column(DateTime, nullable=False, default=datetime.utcnow)
balances = relationship('UserBalance', back_populates='user') balances = relationship('UserBalance', back_populates='user')
internal_transactions = relationship('InternalTransaction', back_populates='user') internal_transactions = relationship('InternalTransaction', back_populates='user')