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


Python ScheduledCall.from_db方法代码示例

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


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

示例1: increment_failure_count

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import from_db [as 别名]
def increment_failure_count(schedule_id):
    """
    Increment the number of consecutive failures, and if it has met or exceeded
    the threshold, disable the schedule.

    :param schedule_id: ID of the schedule whose count should be incremented
    :type  schedule_id: str
    """
    try:
        spec = {'_id': ObjectId(schedule_id)}
    except InvalidId:
        raise exceptions.InvalidValue(['schedule_id'])
    delta = {
        '$inc': {'consecutive_failures': 1},
        '$set': {'last_updated': time.time()},
    }
    schedule = ScheduledCall.get_collection().find_and_modify(
        query=spec, update=delta, new=True)
    if schedule:
        scheduled_call = ScheduledCall.from_db(schedule)
        if scheduled_call.failure_threshold is None or not scheduled_call.enabled:
            return
        if scheduled_call.consecutive_failures >= scheduled_call.failure_threshold:
            _logger.info(_('disabling schedule %(id)s with %(count)d consecutive failures') % {
                'id': schedule_id, 'count': scheduled_call.consecutive_failures
            })
            delta = {'$set': {
                'enabled': False,
                'last_updated': time.time(),
            }}
            ScheduledCall.get_collection().update(spec, delta)
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:33,代码来源:utils.py

示例2: update

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import from_db [as 别名]
def update(schedule_id, delta):
    """
    Updates the schedule with unique ID schedule_id. This only allows updating
    of fields in ScheduledCall.USER_UPDATE_FIELDS.

    :param schedule_id: a unique ID for a schedule
    :type  schedule_id: basestring
    :param delta:       a dictionary of keys with values that should be modified
                        on the schedule.
    :type  delta:       dict

    :return:    instance of ScheduledCall representing the post-update state
    :rtype      ScheduledCall

    :raise  exceptions.UnsupportedValue
    :raise  exceptions.MissingResource
    """
    unknown_keys = set(delta.keys()) - ScheduledCall.USER_UPDATE_FIELDS
    if unknown_keys:
        raise exceptions.UnsupportedValue(list(unknown_keys))

    delta['last_updated'] = time.time()

    try:
        spec = {'_id': ObjectId(schedule_id)}
    except InvalidId:
        raise exceptions.InvalidValue(['schedule_id'])
    schedule = ScheduledCall.get_collection().find_and_modify(
        query=spec, update={'$set': delta}, safe=True, new=True)
    if schedule is None:
        raise exceptions.MissingResource(schedule_id=schedule_id)
    return ScheduledCall.from_db(schedule)
开发者ID:aweiteka,项目名称:pulp,代码行数:34,代码来源:utils.py

示例3: test_values

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import from_db [as 别名]
    def test_values(self):
        schedule = bson.SON(SCHEDULE)
        call = ScheduledCall.from_db(schedule)

        result = call.as_dict()

        self.assertEqual(result['_id'], call.id)
        for k, v in SCHEDULE.items():
            self.assertEqual(v, result[k])
        self.assertTrue('next_run' in result)
开发者ID:aweiteka,项目名称:pulp,代码行数:12,代码来源:test_dispatch.py

示例4: update

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import from_db [as 别名]
def update(schedule_id, delta):
    """
    Updates the schedule with unique ID schedule_id. This only allows updating
    of fields in ScheduledCall.USER_UPDATE_FIELDS.

    :param schedule_id: a unique ID for a schedule
    :type  schedule_id: basestring
    :param delta:       a dictionary of keys with values that should be modified
                        on the schedule.
    :type  delta:       dict

    :return:    instance of ScheduledCall representing the post-update state
    :rtype      ScheduledCall

    :raise  exceptions.UnsupportedValue
    :raise  exceptions.MissingResource
    """
    unknown_keys = set(delta.keys()) - ScheduledCall.USER_UPDATE_FIELDS
    if unknown_keys:
        raise exceptions.UnsupportedValue(list(unknown_keys))

    delta['last_updated'] = time.time()

    # bz 1139703 - if we update iso_schedule, update the pickled object as well
    if 'iso_schedule' in delta:
        interval, start_time, occurrences = dateutils.parse_iso8601_interval(delta['iso_schedule'])
        delta['schedule'] = pickle.dumps(CelerySchedule(interval))

        # set first_run and next_run so that the schedule update will take effect
        new_schedule_call = ScheduledCall(delta['iso_schedule'], 'dummytaskname')
        delta['first_run'] = new_schedule_call.first_run
        delta['next_run'] = new_schedule_call.next_run

    try:
        spec = {'_id': ObjectId(schedule_id)}
    except InvalidId:
        # During schedule update, MissingResource should be raised even if
        # schedule_id is invalid object_id.
        raise exceptions.MissingResource(schedule_id=schedule_id)
    schedule = ScheduledCall.get_collection().find_and_modify(
        query=spec, update={'$set': delta}, new=True)
    if schedule is None:
        raise exceptions.MissingResource(schedule_id=schedule_id)
    return ScheduledCall.from_db(schedule)
开发者ID:BrnoPCmaniak,项目名称:pulp,代码行数:46,代码来源:utils.py

示例5: test_returns_instance

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import from_db [as 别名]
    def test_returns_instance(self):
        call = ScheduledCall.from_db(self.schedule)

        entry = call.as_schedule_entry()

        self.assertTrue(isinstance(entry, celery.beat.ScheduleEntry))
开发者ID:aweiteka,项目名称:pulp,代码行数:8,代码来源:test_dispatch.py

示例6: test_preserves_id

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import from_db [as 别名]
    def test_preserves_id(self):
        call = ScheduledCall.from_db(self.schedule)

        self.assertEqual(call.id, '529f4bd93de3a31d0ec77338')
开发者ID:aweiteka,项目名称:pulp,代码行数:6,代码来源:test_dispatch.py


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