dev@locazia: fix metadata create error

This commit is contained in:
user 2024-03-08 23:14:45 +03:00
parent 962e8dce16
commit 3da514ac15
1 changed files with 26 additions and 19 deletions

View File

@ -1,7 +1,9 @@
import json
import asyncio
from hashlib import sha256
from base58 import b58encode
from datetime import datetime, timedelta
from httpx import AsyncClient
from app.core.logger import make_log
@ -46,7 +48,10 @@ async def create_metadata_for_item(
metadata_hash = sha256(metadata_bin).digest()
metadata_hash_b58 = b58encode(metadata_hash).decode()
metadata_content = None
init_ts = datetime.now()
async with AsyncClient() as client:
while not metadata_content:
response = await client.post(
f"{PROJECT_HOST}/api/v1/storage",
files={"file": ('metadata.json', metadata_bin, 'json')},
@ -65,7 +70,9 @@ async def create_metadata_for_item(
metadata_sha256 = response_json['content_sha256']
metadata_content = db_session.query(StoredContent).filter(StoredContent.hash == metadata_sha256).first()
if metadata_content:
return metadata_content
await asyncio.sleep(.3)
if (datetime.now() - init_ts) > timedelta(seconds=10):
raise Exception("Metadata not created")
return metadata_content