dev@locazia: fix metadata create error
This commit is contained in:
parent
962e8dce16
commit
3da514ac15
|
|
@ -1,7 +1,9 @@
|
||||||
import json
|
import json
|
||||||
|
import asyncio
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
|
|
||||||
from base58 import b58encode
|
from base58 import b58encode
|
||||||
|
from datetime import datetime, timedelta
|
||||||
from httpx import AsyncClient
|
from httpx import AsyncClient
|
||||||
|
|
||||||
from app.core.logger import make_log
|
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 = sha256(metadata_bin).digest()
|
||||||
metadata_hash_b58 = b58encode(metadata_hash).decode()
|
metadata_hash_b58 = b58encode(metadata_hash).decode()
|
||||||
|
|
||||||
|
metadata_content = None
|
||||||
|
init_ts = datetime.now()
|
||||||
async with AsyncClient() as client:
|
async with AsyncClient() as client:
|
||||||
|
while not metadata_content:
|
||||||
response = await client.post(
|
response = await client.post(
|
||||||
f"{PROJECT_HOST}/api/v1/storage",
|
f"{PROJECT_HOST}/api/v1/storage",
|
||||||
files={"file": ('metadata.json', metadata_bin, 'json')},
|
files={"file": ('metadata.json', metadata_bin, 'json')},
|
||||||
|
|
@ -65,7 +70,9 @@ async def create_metadata_for_item(
|
||||||
metadata_sha256 = response_json['content_sha256']
|
metadata_sha256 = response_json['content_sha256']
|
||||||
|
|
||||||
metadata_content = db_session.query(StoredContent).filter(StoredContent.hash == metadata_sha256).first()
|
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")
|
raise Exception("Metadata not created")
|
||||||
|
|
||||||
|
return metadata_content
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue