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


Python ScheduledCall.get_collection方法代码示例

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


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

示例1: tearDown

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [as 别名]
 def tearDown(self):
     super(SchedulerTests, self).tearDown()
     ScheduledCall.get_collection().drop()
     self.scheduler = None
     dispatch_factory.coordinator = self._coordinator_factory
     self._coordinator_factory = None
     dispatch_factory._SCHEDULER = None
开发者ID:bartwo,项目名称:pulp,代码行数:9,代码来源:test_dispatch_scheduler.py

示例2: increment_failure_count

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [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

示例3: delete_by_resource

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [as 别名]
def delete_by_resource(resource):
    """
    Deletes all schedules for the specified resource

    :param resource:    string indicating a unique resource
    :type  resource:    basestring
    """
    ScheduledCall.get_collection().remove({'resource': resource}, safe=True)
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:10,代码来源:utils.py

示例4: delete

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [as 别名]
def delete(schedule_id):
    """
    Deletes the schedule with unique ID schedule_id

    :param schedule_id: a unique ID for a schedule
    :type  schedule_id: basestring
    """
    try:
        ScheduledCall.get_collection().remove({'_id': ObjectId(schedule_id)}, safe=True)
    except InvalidId:
        raise exceptions.InvalidValue(['schedule_id'])
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:13,代码来源:utils.py

示例5: remove

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [as 别名]
 def remove(self, schedule_id):
     """
     Remove a scheduled call request
     @param schedule_id: id of the schedule for the call request
     @type  schedule_id: str
     """
     if isinstance(schedule_id, basestring):
         schedule_id = ObjectId(schedule_id)
     if ScheduledCall.get_collection().find_one(schedule_id) is None:
         raise pulp_exceptions.MissingResource(schedule=str(schedule_id))
     scheduled_call_collection = ScheduledCall.get_collection()
     scheduled_call_collection.remove({'_id': schedule_id}, safe=True)
开发者ID:ehelms,项目名称:pulp,代码行数:14,代码来源:scheduler.py

示例6: reset_failure_count

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [as 别名]
def reset_failure_count(schedule_id):
    """
    Reset the consecutive failure count on a schedule to 0, presumably because
    it ran successfully.

    :param schedule_id: ID of the schedule whose count should be reset
    :type  schedule_id: str
    """
    spec = {'_id': ObjectId(schedule_id)}
    delta = {'$set': {
        'consecutive_failures': 0,
        'last_updated': time.time(),
    }}
    ScheduledCall.get_collection().update(spec=spec, document=delta)
开发者ID:preethit,项目名称:pulp-1,代码行数:16,代码来源:utils.py

示例7: update

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [as 别名]
 def update(self, schedule_id, **schedule_updates):
     """
     Update a scheduled call request
     Valid schedule updates:
      * call_request
      * schedule
      * failure_threshold
      * remaining_runs
      * enabled
     @param schedule_id: id of the schedule for the call request
     @type  schedule_id: str
     @param schedule_updates: updates for scheduled call
     @type  schedule_updates: dict
     """
     if isinstance(schedule_id, basestring):
         schedule_id = ObjectId(schedule_id)
     scheduled_call_collection = ScheduledCall.get_collection()
     if scheduled_call_collection.find_one(schedule_id) is None:
         raise pulp_exceptions.MissingResource(schedule=str(schedule_id))
     validate_schedule_updates(schedule_updates)
     call_request = schedule_updates.pop('call_request', None)
     if call_request is not None:
         schedule_updates['serialized_call_request'] = call_request.serialize()
     schedule = schedule_updates.get('schedule', None)
     if schedule is not None:
         interval, start, runs = dateutils.parse_iso8601_interval(schedule)
         schedule_updates.setdefault('remaining_runs', runs) # honor explicit update
         # XXX (jconnor) it'd be nice to update the next_run if the schedule
         # has changed, but it requires mucking with the internals of the
         # of the scheduled call instance, which is all encapsulated in the
         # ScheduledCall constructor
         # the next_run field will be correctly updated after the next run
     scheduled_call_collection.update({'_id': schedule_id}, {'$set': schedule_updates}, safe=True)
开发者ID:ehelms,项目名称:pulp,代码行数:35,代码来源:scheduler.py

示例8: add

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [as 别名]
 def add(self, call_request, schedule, **schedule_options):
     """
     Add a scheduled call request
     Valid schedule options:
      * failure_threshold: max number of consecutive failures, before scheduled call is disabled, None means no max
      * last_run: datetime of the last run of the call request or None if no last run
      * enabled: boolean flag if the scheduled call is enabled or not
     @param call_request: call request to schedule
     @type  call_request: pulp.server.dispatch.call.CallRequest
     @param schedule: iso8601 formatted interval schedule
     @type  schedule: str
     @param schedule_options: keyword options for this schedule
     @type  schedule_options: dict
     @return: schedule id if successfully scheduled or None otherwise
     @rtype:  str or None
     """
     validate_schedule_options(schedule, schedule_options)
     scheduled_call = ScheduledCall(call_request, schedule, **schedule_options)
     next_run = self.calculate_next_run(scheduled_call)
     if next_run is None:
         return None
     scheduled_call_collection = ScheduledCall.get_collection()
     scheduled_call['next_run'] = next_run
     scheduled_call_collection.insert(scheduled_call, safe=True)
     return str(scheduled_call['_id'])
开发者ID:jlsherrill,项目名称:pulp,代码行数:27,代码来源:scheduler.py

示例9: test_add_no_runs

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [as 别名]
 def test_add_no_runs(self):
     call_request = CallRequest(call)
     schedule_id = self.scheduler.add(call_request, SCHEDULE_0_RUNS)
     self.assertTrue(schedule_id is None)
     collection = ScheduledCall.get_collection()
     cursor = collection.find()
     self.assertTrue(cursor.count() == 0)
开发者ID:ehelms,项目名称:pulp,代码行数:9,代码来源:test_dispatch_scheduler.py

示例10: test_remove

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [as 别名]
 def test_remove(self):
     call_request = CallRequest(call)
     schedule_id = self.scheduler.add(call_request, SCHEDULE_START_TIME)
     self.scheduler.remove(schedule_id)
     collection = ScheduledCall.get_collection()
     scheduled_call = collection.find_one({'_id': schedule_id})
     self.assertTrue(scheduled_call is None)
开发者ID:ehelms,项目名称:pulp,代码行数:9,代码来源:test_dispatch_scheduler.py

示例11: update

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [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

示例12: update_last_run

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [as 别名]
 def update_last_run(self, scheduled_call, call_report=None):
     """
     Update the metadata for a scheduled call that has been run
     @param scheduled_call: scheduled call to be updated
     @type  scheduled_call: dict
     @param call_report: call report from last run, if available
     @type  call_report: CallReport instance or None
     """
     schedule_id = scheduled_call['_id']
     update = {}
     # use scheduled time instead of current to prevent schedule drift
     delta = update.setdefault('$set', {})
     delta['last_run'] = scheduled_call['next_run']
     # if we finished in an error state, make sure we haven't crossed the threshold
     state = getattr(call_report, 'state', None)
     if state == dispatch_constants.CALL_ERROR_STATE:
         inc = update.setdefault('$inc', {})
         inc['consecutive_failures'] = 1
         failure_threshold = scheduled_call['failure_threshold']
         consecutive_failures = scheduled_call['consecutive_failures'] + 1
         if failure_threshold and failure_threshold <= consecutive_failures:
             delta = update.setdefault('$set', {})
             delta['enabled'] = False
             msg = _('Scheduled task [%s] disabled after %d consecutive failures')
             _LOG.error(msg % (schedule_id, consecutive_failures))
     else:
         delta = update.setdefault('$set', {})
         delta['consecutive_failures'] = 0
     # decrement the remaining runs, if we're tracking that
     if scheduled_call['remaining_runs'] is not None:
         inc = update.setdefault('$inc', {})
         inc['remaining_runs'] = -1
     scheduled_call_collection = ScheduledCall.get_collection()
     scheduled_call_collection.update({'_id': schedule_id}, update, safe=True)
开发者ID:jlsherrill,项目名称:pulp,代码行数:36,代码来源:scheduler.py

示例13: __init__

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [as 别名]
    def __init__(self, dispatch_interval=30):
        self.dispatch_interval = dispatch_interval
        self.scheduled_call_collection = ScheduledCall.get_collection()

        self.__exit = False
        self.__lock = threading.RLock()
        self.__condition = threading.Condition(self.__lock)
        self.__dispatcher = None
开发者ID:ryanschneider,项目名称:pulp,代码行数:10,代码来源:scheduler.py

示例14: setUp

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [as 别名]
 def setUp(self):
     super(SchedulerTests, self).setUp()
     pickling.initialize()
     self.scheduler = Scheduler()
     # replace the coordinator so we do not actually execute tasks
     self._coordinator_factory = dispatch_factory.coordinator
     dispatch_factory.coordinator = mock.Mock()
     # NOTE we are not starting the scheduler
     self.scheduled_call_collection = ScheduledCall.get_collection()
开发者ID:ehelms,项目名称:pulp,代码行数:11,代码来源:test_dispatch_scheduler.py

示例15: get_enabled

# 需要导入模块: from pulp.server.db.model.dispatch import ScheduledCall [as 别名]
# 或者: from pulp.server.db.model.dispatch.ScheduledCall import get_collection [as 别名]
def get_enabled():
    """
    Get schedules that are enabled, that is, their "enabled" attribute is True

    :return:    pymongo cursor of ScheduledCall database objects
    :rtype:     pymongo.cursor.Cursor
    """
    criteria = Criteria(filters={'enabled': True})
    return ScheduledCall.get_collection().query(criteria)
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:11,代码来源:utils.py


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