cic-internal-integration/apps/cic-eth/cic_eth/task.py

80 lines
1.7 KiB
Python
Raw Normal View History

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-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
def create_session(self):
logg.warning('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> session from base {}'.format(id(self.session_func)))
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,
sqlalchemy.exc.ResourceClosedError,
2021-03-01 21:15:17 +01:00
)
class CriticalWeb3Task(CriticalTask):
autoretry_for = (
requests.exceptions.ConnectionError,
)
class CriticalSQLAlchemyAndWeb3Task(CriticalTask):
autoretry_for = (
sqlalchemy.exc.DatabaseError,
sqlalchemy.exc.TimeoutError,
requests.exceptions.ConnectionError,
sqlalchemy.exc.ResourceClosedError,
2021-03-07 19:01:16 +01:00
EthError,
2021-03-01 21:15:17 +01:00
)
2021-03-07 14:51:59 +01:00
class CriticalSQLAlchemyAndSignerTask(CriticalTask):
autoretry_for = (
sqlalchemy.exc.DatabaseError,
sqlalchemy.exc.TimeoutError,
sqlalchemy.exc.ResourceClosedError,
2021-03-07 14:51:59 +01:00
SignerError,
)
class CriticalWeb3AndSignerTask(CriticalTask):
autoretry_for = (
requests.exceptions.ConnectionError,
SignerError,
)
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)