diff --git a/icon_stats/crons/cmc_cryptocurrency_quotes_latest.py b/icon_stats/crons/cmc_cryptocurrency_quotes_latest.py index 107d708..864b9a2 100644 --- a/icon_stats/crons/cmc_cryptocurrency_quotes_latest.py +++ b/icon_stats/crons/cmc_cryptocurrency_quotes_latest.py @@ -1,5 +1,6 @@ from icon_stats.log import logger from sqlalchemy.orm import Session +from sqlalchemy.exc import IntegrityError from icon_stats.utils.times import convert_str_date from icon_stats.metrics import prom_metrics @@ -26,8 +27,10 @@ async def run_cmc_cryptocurrency_quotes_latest(): quote['last_updated'] = convert_str_date(quote['last_updated']) exchanges_legacy = CmcListingsLatestQuote(base='ICX', quote='USD', **quote) - - await upsert_model(db_name='stats', model=exchanges_legacy) + try: + await upsert_model(db_name='stats', model=exchanges_legacy) + except IntegrityError: + logger.info("Duplicate PK - skipping upsert") prom_metrics.cron_ran.inc() - logger.info("Ending top tokens cron") + logger.info("Ending cmc crypto quotes latest cron") diff --git a/icon_stats/models/cmc_cryptocurrency_quotes_latest.py b/icon_stats/models/cmc_cryptocurrency_quotes_latest.py index 768ca9f..da61449 100644 --- a/icon_stats/models/cmc_cryptocurrency_quotes_latest.py +++ b/icon_stats/models/cmc_cryptocurrency_quotes_latest.py @@ -22,7 +22,14 @@ class CmcListingsLatestQuote(SQLModel, table=True): market_cap_dominance: float fully_diluted_market_cap: float tvl: float | None - last_updated: datetime.datetime = Column(DateTime(timezone=True), primary_key=True) + # last_updated: datetime.datetime = Column(DateTime(timezone=True), primary_key=True) + # last_updated: datetime.datetime = Field( + # sa_column=Column(DateTime(timezone=True), primary_key=True) + # ) + last_updated: datetime.datetime = Field( + sa_column=Column(DateTime(timezone=True)), + primary_key=True, + ) __table_args__ = {'schema': 'stats'} diff --git a/tests/integration/api/test_api_markets.py b/tests/integration/api/test_api_markets.py index efe66dc..5f4dfc1 100644 --- a/tests/integration/api/test_api_markets.py +++ b/tests/integration/api/test_api_markets.py @@ -6,6 +6,7 @@ def test_api_get_markets(client: TestClient): response = client.get(f"{config.API_REST_PREFIX}/stats/exchanges/legacy") assert response.status_code == 200 + assert response.json()['data']['marketCap'] > 10000000 def test_api_get_prep_error(client: TestClient):