当前位置: 首页>>代码示例>>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;未经允许,请勿转载。