-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add get missing metadata contracts task #58
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,12 +3,14 @@ | |||||
import dramatiq | ||||||
from dramatiq.brokers.redis import RedisBroker | ||||||
from dramatiq.middleware import AsyncIO | ||||||
from periodiq import PeriodiqMiddleware | ||||||
from hexbytes import HexBytes | ||||||
from periodiq import PeriodiqMiddleware, cron | ||||||
from safe_eth.eth.utils import fast_to_checksum_address | ||||||
from sqlmodel.ext.asyncio.session import AsyncSession | ||||||
|
||||||
from app.config import settings | ||||||
from app.datasources.db.database import database_session | ||||||
from app.datasources.db.models import Contract | ||||||
from app.services.contract_metadata_service import get_contract_metadata_service | ||||||
|
||||||
redis_broker = RedisBroker(url=settings.REDIS_URL) | ||||||
|
@@ -35,11 +37,14 @@ async def test_task(message: str) -> None: | |||||
@dramatiq.actor | ||||||
@database_session | ||||||
async def get_contract_metadata_task( | ||||||
address: str, chain_id: int, session: AsyncSession | ||||||
session: AsyncSession, | ||||||
address: str, | ||||||
chain_id: int, | ||||||
skip_attemp_download: bool = False, | ||||||
) -> None: | ||||||
contract_metadata_service = get_contract_metadata_service() | ||||||
# Just try the first time, following retries should be scheduled | ||||||
if await contract_metadata_service.should_attempt_download( | ||||||
if skip_attemp_download or await contract_metadata_service.should_attempt_download( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpicky: |
||||||
session, address, chain_id, 0 | ||||||
): | ||||||
logging.info( | ||||||
|
@@ -61,3 +66,16 @@ async def get_contract_metadata_task( | |||||
) | ||||||
else: | ||||||
logging.debug(f"Skipping contract with address {address} and chain {chain_id}") | ||||||
|
||||||
|
||||||
@dramatiq.actor(periodic=cron("* * * * *")) # Every midnight | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be every midnight not every day. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
@database_session | ||||||
async def get_missing_contract_metadata_task(session: AsyncSession) -> None: | ||||||
async for contract in Contract.get_contracts_without_abi( | ||||||
session, settings.CONTRACT_MAX_DOWNLOAD_RETRIES | ||||||
): | ||||||
get_contract_metadata_task.send( | ||||||
address=HexBytes(contract[0].address).hex(), | ||||||
chain_id=contract[0].chain_id, | ||||||
skip_attemp_download=True, | ||||||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO
max_retries
parameter should be optional and takes 0 as default value. WDYT?