2021-03-04 17:47:13 +01:00
|
|
|
# standard imports
|
|
|
|
|
|
|
|
# third-party imports
|
|
|
|
import celery
|
|
|
|
import sqlalchemy
|
|
|
|
|
|
|
|
# local imports
|
2021-04-09 15:00:15 +02:00
|
|
|
from cic_ussd.error import MetadataStoreError
|
|
|
|
from cic_ussd.db.models.base import SessionBase
|
2021-03-04 17:47:13 +01:00
|
|
|
|
|
|
|
|
2021-04-09 15:00:15 +02:00
|
|
|
class BaseTask(celery.Task):
|
|
|
|
|
|
|
|
session_func = SessionBase.create_session
|
|
|
|
|
|
|
|
def create_session(self):
|
|
|
|
return BaseTask.session_func()
|
|
|
|
|
|
|
|
|
|
|
|
def log_banner(self):
|
|
|
|
logg.debug('task {} root uuid {}'.format(self.__class__.__name__, self.request.root_id))
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
class CriticalTask(BaseTask):
|
2021-03-04 17:47:13 +01:00
|
|
|
retry_jitter = True
|
|
|
|
retry_backoff = True
|
|
|
|
retry_backoff_max = 8
|
|
|
|
|
|
|
|
|
|
|
|
class CriticalSQLAlchemyTask(CriticalTask):
|
|
|
|
autoretry_for = (
|
|
|
|
sqlalchemy.exc.DatabaseError,
|
|
|
|
sqlalchemy.exc.TimeoutError,
|
2021-04-09 15:00:15 +02:00
|
|
|
sqlalchemy.exc.ResourceClosedError,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class CriticalMetadataTask(CriticalTask):
|
|
|
|
autoretry_for = (
|
|
|
|
MetadataStoreError,
|
2021-03-04 17:47:13 +01:00
|
|
|
)
|