当前位置: 首页>>代码示例>>Python>>正文


Python TriggerInstance.delete_by_query方法代码示例

本文整理汇总了Python中st2common.persistence.trigger.TriggerInstance.delete_by_query方法的典型用法代码示例。如果您正苦于以下问题:Python TriggerInstance.delete_by_query方法的具体用法?Python TriggerInstance.delete_by_query怎么用?Python TriggerInstance.delete_by_query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在st2common.persistence.trigger.TriggerInstance的用法示例。


在下文中一共展示了TriggerInstance.delete_by_query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: purge_trigger_instances

# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import delete_by_query [as 别名]
def purge_trigger_instances(logger, timestamp):
    """
    :param timestamp: Trigger instances older than this timestamp will be deleted.
    :type timestamp: ``datetime.datetime
    """
    if not timestamp:
        raise ValueError('Specify a valid timestamp to purge.')

    logger.info('Purging trigger instances older than timestamp: %s' %
                timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))

    query_filters = {'occurrence_time__lt': isotime.parse(timestamp)}

    # TODO: Update this code to return statistics on deleted objects once we
    # upgrade to newer version of MongoDB where delete_by_query actually returns
    # some data

    try:
        TriggerInstance.delete_by_query(**query_filters)
    except InvalidQueryError as e:
        msg = ('Bad query (%s) used to delete trigger instances: %s'
               'Please contact support.' % (query_filters, str(e)))
        raise InvalidQueryError(msg)
    except:
        logger.exception('Deleting instances using query_filters %s failed.', query_filters)

    # Print stats
    logger.info('All trigger instance models older than timestamp %s were deleted.', timestamp)
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:30,代码来源:trigger_instances.py

示例2: purge_trigger_instances

# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import delete_by_query [as 别名]
def purge_trigger_instances(logger, timestamp):
    """
    :param timestamp: Trigger instances older than this timestamp will be deleted.
    :type timestamp: ``datetime.datetime
    """
    if not timestamp:
        raise ValueError('Specify a valid timestamp to purge.')

    logger.info('Purging trigger instances older than timestamp: %s' %
                timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))

    query_filters = {'occurrence_time__lt': isotime.parse(timestamp)}

    try:
        deleted_count = TriggerInstance.delete_by_query(**query_filters)
    except InvalidQueryError as e:
        msg = ('Bad query (%s) used to delete trigger instances: %s'
               'Please contact support.' % (query_filters, str(e)))
        raise InvalidQueryError(msg)
    except:
        logger.exception('Deleting instances using query_filters %s failed.', query_filters)
    else:
        logger.info('Deleted %s trigger instance objects' % (deleted_count))

    # Print stats
    logger.info('All trigger instance models older than timestamp %s were deleted.', timestamp)
开发者ID:lyandut,项目名称:st2,代码行数:28,代码来源:trigger_instances.py


注:本文中的st2common.persistence.trigger.TriggerInstance.delete_by_query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。