Skip to content

Commit

Permalink
[SC-773] Retry count and sleep time of tx as configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
hyerim-kim committed Sep 21, 2023
1 parent a382730 commit f1e79f3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
### Log
Add the below configuration for loguru.
~~~
LOG_ENABLE_MYID_LOGGER=[true|false]
MYIDSDK_LOG_ENABLE_MYID_LOGGER=[true|false]
~~~
4 changes: 2 additions & 2 deletions myid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from myid.config import settings

if settings.LOG_ENABLE_MYID_LOGGER:
if settings.MYIDSDK_LOG_ENABLE_MYID_LOGGER:
logger.enable(__name__)
else:
logger.disable(__name__)

logger.debug(f"LOG_ENABLE_MYID_LOGGER is {settings.LOG_ENABLE_MYID_LOGGER}")
logger.debug(f"{settings.MYIDSDK_LOG_ENABLE_MYID_LOGGER=}")
logger.debug(f"{settings.__repr_name__()}: {settings.dict()}")
6 changes: 4 additions & 2 deletions myid/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@


class MyIdSettings(BaseSettings):
PROJECT_NAME: str = "myid-sdk"
LOG_ENABLE_MYID_LOGGER: bool = False
MYIDSDK_PROJECT_NAME: str = "myid-sdk"
MYIDSDK_TX_RETRY_COUNT: int = 5
MYIDSDK_TX_SLEEP_TIME: int = 2
MYIDSDK_LOG_ENABLE_LOGGER: bool = False

class Config:
case_sensitive = True
Expand Down
5 changes: 3 additions & 2 deletions myid/credential_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from iconsdk.wallet.wallet import KeyWallet, Wallet
from loguru import logger

from myid import settings
from myid.score.credential_info_score import CredentialInfoScore


Expand Down Expand Up @@ -39,7 +40,7 @@ async def _get_transaction_result(self, tx_hash: str) -> dict:
:return:
"""
response = None
retry_times = 5
retry_times = settings.MYIDSDK_TX_RETRY_COUNT
while response is None and retry_times > 0:
try:
tx_result = self._icon_service.get_transaction_result(tx_hash)
Expand All @@ -54,7 +55,7 @@ async def _get_transaction_result(self, tx_hash: str) -> dict:
retry_times -= 1
logger.debug(f"Remain to retry request for getting transaction result: {retry_times}")

await asyncio.sleep(2)
await asyncio.sleep(settings.MYIDSDK_TX_SLEEP_TIME)
continue

return tx_result
Expand Down

0 comments on commit f1e79f3

Please sign in to comment.