2021-03-01 21:15:17 +01:00
|
|
|
# import
|
2021-03-11 11:40:02 +01:00
|
|
|
import time
|
2021-03-01 21:15:17 +01:00
|
|
|
import requests
|
2021-03-11 11:40:02 +01:00
|
|
|
import logging
|
|
|
|
import uuid
|
2021-03-01 21:15:17 +01:00
|
|
|
|
|
|
|
# external imports
|
|
|
|
import celery
|
|
|
|
import sqlalchemy
|
2021-03-17 11:24:55 +01:00
|
|
|
from chainlib.eth.constant import ZERO_ADDRESS
|
|
|
|
from chainlib.eth.nonce import RPCNonceOracle
|
|
|
|
from chainlib.eth.gas import RPCGasOracle
|
2021-03-01 21:15:17 +01:00
|
|
|
|
2021-03-07 14:51:59 +01:00
|
|
|
# local imports
|
2021-03-07 19:01:16 +01:00
|
|
|
from cic_eth.error import (
|
|
|
|
SignerError,
|
|
|
|
EthError,
|
|
|
|
)
|
2021-03-11 11:40:02 +01:00
|
|
|
from cic_eth.db.models.base import SessionBase
|
2021-03-07 14:51:59 +01:00
|
|
|
|
2021-03-11 11:40:02 +01:00
|
|
|
logg = logging.getLogger(__name__)
|
2021-03-01 21:15:17 +01:00
|
|
|
|
2021-03-11 11:40:02 +01:00
|
|
|
celery_app = celery.current_app
|
|
|
|
|
|
|
|
|
|
|
|
class BaseTask(celery.Task):
|
|
|
|
|
|
|
|
session_func = SessionBase.create_session
|
2021-03-17 11:24:55 +01:00
|
|
|
call_address = ZERO_ADDRESS
|
|
|
|
create_nonce_oracle = RPCNonceOracle
|
|
|
|
create_gas_oracle = RPCGasOracle
|
2021-03-11 11:40:02 +01:00
|
|
|
|
|
|
|
def create_session(self):
|
|
|
|
return BaseTask.session_func()
|
|
|
|
|
|
|
|
|
|
|
|
class CriticalTask(BaseTask):
|
2021-03-01 21:15:17 +01:00
|
|
|
retry_jitter = True
|
|
|
|
retry_backoff = True
|
|
|
|
retry_backoff_max = 8
|
|
|
|
|
|
|
|
|
|
|
|
class CriticalSQLAlchemyTask(CriticalTask):
|
|
|
|
autoretry_for = (
|
|
|
|
sqlalchemy.exc.DatabaseError,
|
|
|
|
sqlalchemy.exc.TimeoutError,
|
2021-03-09 07:43:31 +01:00
|
|
|
sqlalchemy.exc.ResourceClosedError,
|
2021-03-01 21:15:17 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class CriticalWeb3Task(CriticalTask):
|
|
|
|
autoretry_for = (
|
|
|
|
requests.exceptions.ConnectionError,
|
|
|
|
)
|
2021-03-18 11:57:26 +01:00
|
|
|
safe_gas_threshold_amount = 2000000000 * 60000 * 3
|
2021-03-18 19:36:52 +01:00
|
|
|
safe_gas_refill_amount = safe_gas_threshold_amount * 5
|
2021-03-01 21:15:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
class CriticalSQLAlchemyAndWeb3Task(CriticalTask):
|
|
|
|
autoretry_for = (
|
|
|
|
sqlalchemy.exc.DatabaseError,
|
|
|
|
sqlalchemy.exc.TimeoutError,
|
|
|
|
requests.exceptions.ConnectionError,
|
2021-03-09 07:43:31 +01:00
|
|
|
sqlalchemy.exc.ResourceClosedError,
|
2021-03-07 19:01:16 +01:00
|
|
|
EthError,
|
2021-03-01 21:15:17 +01:00
|
|
|
)
|
2021-03-18 11:57:26 +01:00
|
|
|
safe_gas_threshold_amount = 2000000000 * 60000 * 3
|
2021-03-18 19:36:52 +01:00
|
|
|
safe_gas_refill_amount = safe_gas_threshold_amount * 5
|
|
|
|
|
2021-03-07 14:51:59 +01:00
|
|
|
|
|
|
|
class CriticalSQLAlchemyAndSignerTask(CriticalTask):
|
|
|
|
autoretry_for = (
|
|
|
|
sqlalchemy.exc.DatabaseError,
|
|
|
|
sqlalchemy.exc.TimeoutError,
|
2021-03-09 07:43:31 +01:00
|
|
|
sqlalchemy.exc.ResourceClosedError,
|
2021-03-07 14:51:59 +01:00
|
|
|
SignerError,
|
|
|
|
)
|
|
|
|
|
|
|
|
class CriticalWeb3AndSignerTask(CriticalTask):
|
|
|
|
autoretry_for = (
|
|
|
|
requests.exceptions.ConnectionError,
|
|
|
|
SignerError,
|
|
|
|
)
|
2021-03-18 19:36:52 +01:00
|
|
|
safe_gas_threshold_amount = 2000000000 * 60000 * 3
|
|
|
|
safe_gas_refill_amount = safe_gas_threshold_amount * 5
|
2021-03-11 11:40:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
@celery_app.task(bind=True, base=BaseTask)
|
|
|
|
def hello(self):
|
|
|
|
time.sleep(0.1)
|
|
|
|
return id(SessionBase.create_session)
|