本文整理汇总了Python中pulp.server.db.model.TaskStatus.objects方法的典型用法代码示例。如果您正苦于以下问题:Python TaskStatus.objects方法的具体用法?Python TaskStatus.objects怎么用?Python TaskStatus.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp.server.db.model.TaskStatus
的用法示例。
在下文中一共展示了TaskStatus.objects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_task_status_update_fires_notification
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def test_task_status_update_fires_notification(self, mock_send):
"""
Test that update_one() also fires a notification.
"""
task_id = self.get_random_uuid()
worker_name = 'special_worker_name'
tags = ['test-tag1', 'test-tag2']
state = 'waiting'
ts = TaskStatus(task_id, worker_name, tags, state)
ts.save()
# ensure event was fired for save()
mock_send.assert_called_once_with(ts, routing_key="tasks.%s" % task_id)
now = datetime.now(dateutils.utc_tz())
start_time = dateutils.format_iso8601_datetime(now)
delta = {'start_time': start_time,
'state': 'running',
'progress_report': {'report-id': 'my-progress'}}
self.assertEquals(len(mock_send.call_args_list), 1)
TaskStatus.objects(task_id=task_id).update_one(
set__start_time=delta['start_time'], set__state=delta['state'],
set__progress_report=delta['progress_report'])
# ensure event was fired for update_one()
self.assertEquals(len(mock_send.call_args_list), 2)
mock_send.assert_called_with(ts, routing_key="tasks.%s" % task_id)
示例2: test_task_status_update
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def test_task_status_update(self):
"""
Tests the successful operation of task status update.
"""
task_id = self.get_random_uuid()
worker_name = 'special_worker_name'
tags = ['test-tag1', 'test-tag2']
state = 'waiting'
TaskStatus(task_id, worker_name, tags, state).save()
now = datetime.now(dateutils.utc_tz())
start_time = dateutils.format_iso8601_datetime(now)
delta = {'start_time': start_time,
'state': 'running',
'progress_report': {'report-id': 'my-progress'}}
TaskStatus.objects(task_id=task_id).update_one(
set__start_time=delta['start_time'], set__state=delta['state'],
set__progress_report=delta['progress_report'])
task_status = TaskStatus.objects(task_id=task_id).first()
self.assertEqual(task_status['start_time'], delta['start_time'])
# Make sure that parse_iso8601_datetime is able to parse the start_time without errors
dateutils.parse_iso8601_datetime(task_status['start_time'])
self.assertEqual(task_status['state'], delta['state'])
self.assertEqual(task_status['progress_report'], delta['progress_report'])
self.assertEqual(task_status['worker_name'], worker_name)
示例3: __call__
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def __call__(self, *args, **kwargs):
"""
This overrides CeleryTask's __call__() method. We use this method
for task state tracking of Pulp tasks.
"""
# Check task status and skip running the task if task state is 'canceled'.
try:
task_status = TaskStatus.objects.get(task_id=self.request.id)
except DoesNotExist:
task_status = None
if task_status and task_status['state'] == constants.CALL_CANCELED_STATE:
_logger.debug("Task cancel received for task-id : [%s]" % self.request.id)
return
# Update start_time and set the task state to 'running' for asynchronous tasks.
# Skip updating status for eagerly executed tasks, since we don't want to track
# synchronous tasks in our database.
if not self.request.called_directly:
now = datetime.now(dateutils.utc_tz())
start_time = dateutils.format_iso8601_datetime(now)
# Using 'upsert' to avoid a possible race condition described in the apply_async method
# above.
TaskStatus.objects(task_id=self.request.id).update_one(
set__state=constants.CALL_RUNNING_STATE, set__start_time=start_time, upsert=True)
# Run the actual task
_logger.debug("Running task : [%s]" % self.request.id)
return super(Task, self).__call__(*args, **kwargs)
示例4: clean
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def clean(self):
super(RepoManagerTests, self).clean()
model.Repository.objects.delete()
model.Importer.objects.delete()
model.Distributor.objects.delete()
TaskStatus.objects().delete()
示例5: clean
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def clean(self):
super(RepoManagerTests, self).clean()
model.Repository.drop_collection()
RepoImporter.get_collection().remove()
RepoDistributor.get_collection().remove()
TaskStatus.objects().delete()
示例6: failed
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def failed(self, reply):
"""
Notification (reply) indicating an RMI failed.
This information used to update the task status.
:param reply: A failure reply object.
:type reply: gofer.rmi.async.Failed
"""
_logger.info(_('Task RMI (failed): %(r)s'), {'r': reply})
call_context = dict(reply.data)
action = call_context.get('action')
task_id = call_context['task_id']
traceback = reply.xstate['trace']
finished = reply.timestamp
if not finished:
now = datetime.now(dateutils.utc_tz())
finished = dateutils.format_iso8601_datetime(now)
TaskStatus.objects(task_id=task_id).update_one(set__finish_time=finished,
set__state=constants.CALL_ERROR_STATE,
set__traceback=traceback)
if action == 'bind':
ReplyHandler._bind_failed(task_id, call_context)
return
if action == 'unbind':
ReplyHandler._unbind_failed(task_id, call_context)
return
示例7: cancel
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def cancel(task_id):
"""
Cancel the task that is represented by the given task_id. This method cancels only the task
with given task_id, not the spawned tasks. This also updates task's state to 'canceled'.
:param task_id: The ID of the task you wish to cancel
:type task_id: basestring
:raises MissingResource: if a task with given task_id does not exist
:raises PulpCodedException: if given task is already in a complete state
"""
try:
task_status = TaskStatus.objects.get(task_id=task_id)
except DoesNotExist:
raise MissingResource(task_id)
if task_status['state'] in constants.CALL_COMPLETE_STATES:
# If the task is already done, just stop
msg = _('Task [%(task_id)s] already in a completed state: %(state)s')
_logger.info(msg % {'task_id': task_id, 'state': task_status['state']})
return
controller.revoke(task_id, terminate=True)
TaskStatus.objects(task_id=task_id, state__nin=constants.CALL_COMPLETE_STATES).\
update_one(set__state=constants.CALL_CANCELED_STATE)
msg = _('Task canceled: %(task_id)s.')
msg = msg % {'task_id': task_id}
_logger.info(msg)
示例8: set_progress
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def set_progress(self, status):
"""
Informs the server of the current state of the publish operation. The
contents of the status is dependent on how the distributor
implementation chooses to divide up the publish process.
@param status: contains arbitrary data to describe the state of the
publish; the contents may contain whatever information is relevant
to the distributor implementation so long as it is serializable
"""
if self.task_id is None:
# not running within a task
return
try:
self.progress_report[self.report_id] = status
TaskStatus.objects(task_id=self.task_id).update_one(
set__progress_report=self.progress_report)
except Exception, e:
_logger.exception(
'Exception from server setting progress for report [%s]' % self.report_id)
try:
_logger.error('Progress value: %s' % str(status))
except Exception:
# Best effort to print this, but if its that grossly unserializable
# the log will tank and we don't want that exception to bubble up
pass
raise self.exception_class(e), None, sys.exc_info()[2]
示例9: succeeded
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def succeeded(self, reply):
"""
Notification (reply) indicating an RMI succeeded.
This information is relayed to the task coordinator.
:param reply: A successful reply object.
:type reply: gofer.rmi.async.Succeeded
"""
_logger.info(_('Task RMI (succeeded): %(r)s'), {'r': reply})
call_context = dict(reply.data)
action = call_context.get('action')
task_id = call_context['task_id']
result = dict(reply.retval)
finished = reply.timestamp
if not finished:
now = datetime.now(dateutils.utc_tz())
finished = dateutils.format_iso8601_datetime(now)
TaskStatus.objects(task_id=task_id).update_one(set__finish_time=finished,
set__state=constants.CALL_FINISHED_STATE,
set__result=result)
if action == 'bind':
if result['succeeded']:
ReplyHandler._bind_succeeded(task_id, call_context)
else:
ReplyHandler._bind_failed(task_id, call_context)
return
if action == 'unbind':
if result['succeeded']:
ReplyHandler._unbind_succeeded(call_context)
else:
ReplyHandler._unbind_failed(task_id, call_context)
return
示例10: test_set_accepted
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def test_set_accepted(self):
task_id = self.get_random_uuid()
TaskStatus(task_id, state=constants.CALL_WAITING_STATE).save()
TaskStatus.objects(task_id=task_id, state=constants.CALL_WAITING_STATE).\
update_one(set__state=constants.CALL_ACCEPTED_STATE)
task_status = TaskStatus.objects.get(task_id=task_id)
self.assertTrue(task_status['state'], constants.CALL_ACCEPTED_STATE)
示例11: apply_async_with_reservation
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def apply_async_with_reservation(self, resource_type, resource_id, *args, **kwargs):
"""
This method allows the caller to schedule the ReservedTask to run asynchronously just like
Celery's apply_async(), while also making the named resource. No two tasks that claim the
same resource reservation can execute concurrently. It accepts type and id of a resource
and combines them to form a resource id.
This does not dispatch the task directly, but instead promises to dispatch it later by
encapsulating the desired task through a call to a _queue_reserved_task task. See the
docblock on _queue_reserved_task for more information on this.
This method creates a TaskStatus as a placeholder for later updates. Pulp expects to poll
on a task just after calling this method, so a TaskStatus entry needs to exist for it
before it returns.
For a list of parameters accepted by the *args and **kwargs parameters, please see the
docblock for the apply_async() method.
:param resource_type: A string that identifies type of a resource
:type resource_type: basestring
:param resource_id: A string that identifies some named resource, guaranteeing that only
one task reserving this same string can happen at a time.
:type resource_id: basestring
:param tags: A list of tags (strings) to place onto the task, used for searching
for tasks by tag
:type tags: list
:param group_id: The id to identify which group of tasks a task belongs to
:type group_id: uuid.UUID
:return: An AsyncResult instance as returned by Celery's apply_async
:rtype: celery.result.AsyncResult
"""
# Form a resource_id for reservation by combining given resource type and id. This way,
# two different resources having the same id will not block each other.
resource_id = ":".join((resource_type, resource_id))
inner_task_id = str(uuid.uuid4())
task_name = self.name
tag_list = kwargs.get('tags', [])
group_id = kwargs.get('group_id', None)
# Create a new task status with the task id and tags.
task_status = TaskStatus(task_id=inner_task_id, task_type=task_name,
state=constants.CALL_WAITING_STATE, tags=tag_list,
group_id=group_id)
# To avoid the race condition where __call__ method below is called before
# this change is propagated to all db nodes, using an 'upsert' here and setting
# the task state to 'waiting' only on an insert.
task_status.save_with_set_on_insert(fields_to_set_on_insert=['state', 'start_time'])
try:
_queue_reserved_task.apply_async(
args=[task_name, inner_task_id, resource_id, args, kwargs],
queue=RESOURCE_MANAGER_QUEUE
)
except Exception:
TaskStatus.objects(task_id=task_status.task_id).update(state=constants.CALL_ERROR_STATE)
raise
return AsyncResult(inner_task_id)
示例12: progress
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def progress(self, reply):
"""
Notification (reply) indicating an RMI has reported status.
This information is relayed to the task coordinator.
:param reply: A progress reply object.
:type reply: gofer.rmi.async.Progress
"""
call_context = dict(reply.data)
task_id = call_context['task_id']
TaskStatus.objects(task_id=task_id).update_one(set__progress_report=reply.details)
示例13: accepted
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def accepted(self, reply):
"""
Notification that an RMI has started executing in the agent.
The task status is updated in the pulp DB.
:param reply: A status reply object.
:type reply: gofer.rmi.async.Accepted
"""
_logger.debug(_('Task RMI (accepted): %(r)s'), {'r': reply})
call_context = dict(reply.data)
task_id = call_context['task_id']
TaskStatus.objects(task_id=task_id, state=constants.CALL_WAITING_STATE).\
update_one(set__state=constants.CALL_ACCEPTED_STATE)
示例14: apply_async
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def apply_async(self, *args, **kwargs):
"""
A wrapper around the PulpTask apply_async method. It allows us to accept a few more
parameters than Celery does for our own purposes, listed below. It also allows us
to create and update task status which can be used to track status of this task
during it's lifetime.
:param queue: The queue that the task has been placed into (optional, defaults to
the general Celery queue.)
:type queue: basestring
:param tags: A list of tags (strings) to place onto the task, used for searching for
tasks by tag
:type tags: list
:param group_id: The id that identifies which group of tasks a task belongs to
:type group_id: uuid.UUID
:return: An AsyncResult instance as returned by Celery's apply_async
:rtype: celery.result.AsyncResult
"""
if celery_version.startswith('4'):
routing_key = kwargs.get('routing_key',
defaults.NAMESPACES['task']['default_routing_key'].default)
else:
routing_key = kwargs.get('routing_key',
defaults.NAMESPACES['CELERY']['DEFAULT_ROUTING_KEY'].default)
tag_list = kwargs.pop('tags', [])
group_id = kwargs.pop('group_id', None)
try:
async_result = super(Task, self).apply_async(*args, **kwargs)
except Exception:
if 'task_id' in kwargs:
TaskStatus.objects(task_id=kwargs['task_id']).update(
state=constants.CALL_ERROR_STATE
)
raise
async_result.tags = tag_list
# Create a new task status with the task id and tags.
task_status = TaskStatus(
task_id=async_result.id, task_type=self.name,
state=constants.CALL_WAITING_STATE, worker_name=routing_key, tags=tag_list,
group_id=group_id)
# We're now racing with __call__, on_failure and on_success, any of which may
# have completed by now. To avoid overwriting TaskStatus updates from those callbacks,
# we'll do an upsert and only touch the fields listed below if we've inserted the object.
task_status.save_with_set_on_insert(fields_to_set_on_insert=[
'state', 'start_time', 'finish_time', 'result', 'error',
'spawned_tasks', 'traceback'])
return async_result
示例15: test_set_failed_with_timestamp
# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import objects [as 别名]
def test_set_failed_with_timestamp(self):
task_id = self.get_random_uuid()
TaskStatus(task_id).save()
traceback = 'abcdef'
finished = '2014-11-21 05:21:38.829678'
TaskStatus.objects(task_id=task_id).update_one(set__finish_time=finished,
set__state=constants.CALL_ERROR_STATE,
set__traceback=traceback)
task_status = TaskStatus.objects.get(task_id=task_id)
self.assertTrue(task_status['state'], constants.CALL_ERROR_STATE)
self.assertTrue(task_status['finish_time'], finished)
self.assertTrue(task_status['traceback'], traceback)