當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.InterfaceError方法代碼示例

本文整理匯總了Python中django.db.utils.InterfaceError方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.InterfaceError方法的具體用法?Python utils.InterfaceError怎麽用?Python utils.InterfaceError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.db.utils的用法示例。


在下文中一共展示了utils.InterfaceError方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: render_path

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import InterfaceError [as 別名]
def render_path(self, *args, **kwargs):
        # Retry after an InterfaceError
        max_attempts = 5
        for i in range(max_attempts):
            try:
                return super().render_path(*args, **kwargs)
            except InterfaceError as e:
                self.logger.warning("Caught InterfaceError, closing connection "
                                    "and trying again (attempt #%s)",
                                    i, exc_info=True)
                try:
                    connection.close()
                except:
                    pass

        self.logger.error("Failed to render page after %s attempts. "
                          "Re-raising last exception...", max_attempts)
        raise e 
開發者ID:chaoss,項目名稱:prospector,代碼行數:20,代碼來源:renderers.py

示例2: task_completed

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import InterfaceError [as 別名]
def task_completed(sender=None, **kwargs):
    task_kwargs = kwargs.get('kwargs')
    job_id = task_kwargs.get('wooey_job')
    # Just return if it is not a wooey_job!
    if not job_id:
        return

    from .models import WooeyJob
    from celery import states
    try:
        job = WooeyJob.objects.get(pk=job_id)
    except (InterfaceError, DatabaseError) as e:
        db.connection.close()
        job = WooeyJob.objects.get(pk=job_id)
    state = kwargs.get('state')
    if state:
        job.status = WooeyJob.COMPLETED if state == states.SUCCESS else state
    job.celery_id = kwargs.get('task_id')
    job.save() 
開發者ID:wooey,項目名稱:Wooey,代碼行數:21,代碼來源:signals.py

示例3: process_exception

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import InterfaceError [as 別名]
def process_exception(self, request, exception):
        """Raise 424 on InterfaceError."""
        if isinstance(exception, InterfaceError):
            DB_CONNECTION_ERRORS_COUNTER.inc()
            LOG.error("KokuTenantMiddleware InterfaceError exception: %s", exception)
            return HttpResponseFailedDependency({"source": "Database", "exception": exception}) 
開發者ID:project-koku,項目名稱:koku,代碼行數:8,代碼來源:middleware.py

示例4: run

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import InterfaceError [as 別名]
def run(self):
        """The main run loop of the thread
        """

        logger.info('%s thread started', self._name)

        while self._running:

            started = now()

            try:
                self._execute()
            except InterfaceError as err:
                logger.exception('%s thread had a critical error interfacing with the database', self._name)
                if err.message == 'connection already closed':
                    msg = '%s thread has detected that the database connection is closed and cannot be recovered.'
                    msg += ' Shutting down the scheduler...'
                    logger.error(msg, self._name)
                    from scheduler.management.commands.scale_scheduler import GLOBAL_SHUTDOWN
                    GLOBAL_SHUTDOWN()
            except Exception:
                logger.exception('%s thread had a critical error', self._name)

            duration = now() - started

            msg = '%s thread loop took %.3f seconds'
            if duration > self._warning_threshold:
                logger.warning(msg, self._name, duration.total_seconds())
            else:
                logger.debug(msg, self._name, duration.total_seconds())

            # If time takes less than threshold, throttle
            if duration < self._throttle:
                # Delay until full throttle time reached
                delay = math.ceil(self._throttle.total_seconds() - duration.total_seconds())
                time.sleep(delay)

        logger.info('%s thread stopped', self._name) 
開發者ID:ngageoint,項目名稱:scale,代碼行數:40,代碼來源:base_thread.py

示例5: task_completed

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import InterfaceError [as 別名]
def task_completed(sender=None, **kwargs):
    task_kwargs = kwargs.get('kwargs')
    job_id = task_kwargs.get('djangui_job')
    from .models import DjanguiJob
    from celery import states
    try:
        job = DjanguiJob.objects.get(pk=job_id)
    except (InterfaceError, DatabaseError) as e:
        db.connection.close()
        job = DjanguiJob.objects.get(pk=job_id)
    state = kwargs.get('state')
    if state:
        job.status = DjanguiJob.COMPLETED if state == states.SUCCESS else state
    job.celery_id = kwargs.get('task_id')
    job.save() 
開發者ID:Chris7,項目名稱:django-djangui,代碼行數:17,代碼來源:signals.py

示例6: transaction_retry

# 需要導入模塊: from django.db import utils [as 別名]
# 或者: from django.db.utils import InterfaceError [as 別名]
def transaction_retry(max_retries=1):
    """Decorator to retry database operations.

    For functions doing database operations, adding
    retrying if the operation fails.

    Keyword Arguments:
        max_retries (int): Maximum number of retries.  Default one retry.
    """

    def _outer(fun):

        @wraps(fun)
        def _inner(*args, **kwargs):
            _max_retries = kwargs.pop('exception_retry_count', max_retries)
            for retries in count(0):
                try:
                    return fun(*args, **kwargs)
                except SchedulingError as e:
                    log_task_failure(e, *args, **kwargs)
                    TaskUtils.prepare_task_execution()
                    if retries >= _max_retries:
                        raise
                except InterfaceError as e:
                    log_task_failure(e, *args, **kwargs)
                    TaskUtils.prepare_task_execution()
                    if retries >= _max_retries:
                        raise
                except OperationalError as e:
                    log_task_failure(e, *args, **kwargs)
                    TaskUtils.prepare_task_execution()
                    if retries >= _max_retries:
                        raise
                except Exception as e:  # pragma: no cover
                    # Depending on the database backend used we can experience
                    # various exceptions. E.g. psycopg2 raises an exception
                    # if some operation breaks the transaction, so saving
                    # the task result won't be possible until we rollback
                    # the transaction.
                    log_task_failure(e, *args, **kwargs)
                    if retries >= _max_retries:
                        raise

        return _inner

    return _outer 
開發者ID:LexPredict,項目名稱:lexpredict-contraxsuite,代碼行數:48,代碼來源:managers.py


注:本文中的django.db.utils.InterfaceError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。