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


Python TaskStatus.save方法代码示例

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


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

示例1: test_task_status_update_fires_notification

# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import save [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)
开发者ID:credativ,项目名称:pulp,代码行数:28,代码来源:test_dispatch.py

示例2: test_save_update_with_set_on_insert

# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import save [as 别名]
    def test_save_update_with_set_on_insert(self):
        """
        Test the save method with set on insert arguments when the object is already in the
        database.
        """
        task_id = str(uuid4())
        worker_name = 'worker_name'
        tags = ['tag_1', 'tag_2']
        state = constants.CALL_ACCEPTED_STATE
        spawned_tasks = ['foo']
        error = {'error': 'some_error'}
        progress_report = {'what do we want?': 'progress!', 'when do we want it?': 'now!'}
        task_type = 'some.task'
        old_start_time = start_time = datetime.now()
        finish_time = start_time + timedelta(minutes=5)
        start_time = dateutils.format_iso8601_datetime(start_time)
        finish_time = dateutils.format_iso8601_datetime(finish_time)
        result = None
        ts = TaskStatus(
            task_id, worker_name, tags, state, spawned_tasks=spawned_tasks, error=error,
            progress_report=progress_report, task_type=task_type, start_time=start_time,
            finish_time=finish_time, result=result)
        # Put the object in the database, and then change some of it settings.
        ts.save()
        new_worker_name = 'a different_worker'
        new_state = constants.CALL_SUSPENDED_STATE
        new_start_time = old_start_time + timedelta(minutes=10)
        new_start_time = dateutils.format_iso8601_datetime(new_start_time)
        ts.worker_name = new_worker_name
        ts.state = new_state
        ts.start_time = new_start_time

        # This should update the worker_name on ts in the database, but should not update the state
        # or start_time
        ts.save_with_set_on_insert(fields_to_set_on_insert=['state', 'start_time'])

        ts = TaskStatus.objects()
        # There should only be one TaskStatus in the db
        self.assertEqual(len(ts), 1)
        ts = ts[0]
        # Make sure all the attributes are correct
        self.assertEqual(ts['task_id'], task_id)
        # Queue should have been updated
        self.assertEqual(ts['worker_name'], new_worker_name)
        self.assertEqual(ts['tags'], tags)
        # state should not have been updated
        self.assertEqual(ts['state'], state)
        self.assertEqual(ts['error'], error)
        self.assertEqual(ts['spawned_tasks'], spawned_tasks)
        self.assertEqual(ts['progress_report'], progress_report)
        self.assertEqual(ts['task_type'], task_type)
        # start_time should not have been updated
        self.assertEqual(ts['start_time'], start_time)
        self.assertEqual(ts['finish_time'], finish_time)
        self.assertEqual(ts['result'], result)
        # These are always None
        self.assertEqual(ts['traceback'], None)
        self.assertEqual(ts['exception'], None)
开发者ID:credativ,项目名称:pulp,代码行数:60,代码来源:test_dispatch.py

示例3: test_save_task_status_fires_notification

# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import save [as 别名]
    def test_save_task_status_fires_notification(self, mock_send):
        """
        Test that saving a TaskStatus fires an event notification.
        """
        task_id = self.get_random_uuid()

        ts = TaskStatus(task_id)
        ts.save()

        mock_send.assert_called_once_with(ts, routing_key="tasks.%s" % task_id)
开发者ID:credativ,项目名称:pulp,代码行数:12,代码来源:test_dispatch.py

示例4: test_data_call

# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import save [as 别名]
    def test_data_call(self, mock_current_task):
        mock_current_task.request.id = 'fake_id'
        fake_task_status = TaskStatus('fake_id')
        fake_task_status.save()
        data = {'event_type': 'test_type',
                'payload': 'test_payload',
                'call_report': fake_task_status}

        event = event_data.Event(data['event_type'], data['payload'])

        self.assertEqual(data, event.data())
开发者ID:credativ,项目名称:pulp,代码行数:13,代码来源:test_crud.py

示例5: test_illegal_multi_arg

# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import save [as 别名]
 def test_illegal_multi_arg(self):
     """
     Test that we receive an exception if we try to use the 'multi' kwarg
     """
     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()
     self.assertRaises(NotImplementedError, TaskStatus.objects(task_id=task_id).update_one,
                       multi=True)
开发者ID:credativ,项目名称:pulp,代码行数:14,代码来源:test_dispatch.py

示例6: test_event_instantiation

# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import save [as 别名]
    def test_event_instantiation(self, mock_current_task):
        mock_current_task.request.id = 'fake_id'
        fake_task_status = TaskStatus('fake_id')
        fake_task_status.save()

        event_type = 'test_type'
        payload = 'test_payload'

        try:
            event = event_data.Event(event_type, payload)
        except Exception, e:
            self.fail(e.message)
开发者ID:credativ,项目名称:pulp,代码行数:14,代码来源:test_crud.py

示例7: test_data_call

# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import save [as 别名]
    def test_data_call(self, mock_current_task, mock_task_serializer):
        mock_current_task.request.id = 'fake_id'
        fake_task_status = TaskStatus('fake_id')
        fake_task_status.save()
        data = {'event_type': 'test_type',
                'payload': 'test_payload',
                'call_report': fake_task_status}

        event = event_data.Event(data['event_type'], data['payload'])

        data['call_report'] = mock_task_serializer.return_value
        self.assertDictEqual(data, event.data())
        mock_task_serializer.assert_called_once_with(fake_task_status)
开发者ID:alanoe,项目名称:pulp,代码行数:15,代码来源:test_crud.py

示例8: test_save_update_defaults

# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import save [as 别名]
    def test_save_update_defaults(self):
        """
        Test the save method with default arguments when the object is already in the database.
        """
        task_id = str(uuid4())
        worker_name = 'worker_name'
        tags = ['tag_1', 'tag_2']
        state = constants.CALL_ACCEPTED_STATE
        spawned_tasks = ['foo']
        error = {'error': 'some_error'}
        progress_report = {'what do we want?': 'progress!', 'when do we want it?': 'now!'}
        task_type = 'some.task'
        start_time = datetime.now()
        finish_time = start_time + timedelta(minutes=5)
        start_time = dateutils.format_iso8601_datetime(start_time)
        finish_time = dateutils.format_iso8601_datetime(finish_time)
        result = None
        ts = TaskStatus(
            task_id, worker_name, tags, state, spawned_tasks=spawned_tasks, error=error,
            progress_report=progress_report, task_type=task_type, start_time=start_time,
            finish_time=finish_time, result=result)
        # Let's go ahead and insert the object
        ts.save()
        # Now let's alter it a bit, and make sure the alteration makes it to the DB correctly.
        new_state = constants.CALL_RUNNING_STATE
        ts.state = new_state

        # This should update ts in the database
        ts.save()

        ts = TaskStatus.objects()
        # There should only be one TaskStatus in the db
        self.assertEqual(len(ts), 1)
        ts = ts[0]
        # Make sure all the attributes are correct
        self.assertEqual(ts['task_id'], task_id)
        self.assertEqual(ts['worker_name'], worker_name)
        self.assertEqual(ts['tags'], tags)
        # The state should have been updated
        self.assertEqual(ts['state'], new_state)
        self.assertEqual(ts['error'], error)
        self.assertEqual(ts['spawned_tasks'], spawned_tasks)
        self.assertEqual(ts['progress_report'], progress_report)
        self.assertEqual(ts['task_type'], task_type)
        self.assertEqual(ts['start_time'], start_time)
        self.assertEqual(ts['finish_time'], finish_time)
        self.assertEqual(ts['result'], result)
        # These are always None
        self.assertEqual(ts['traceback'], None)
        self.assertEqual(ts['exception'], None)
开发者ID:credativ,项目名称:pulp,代码行数:52,代码来源:test_dispatch.py

示例9: test_save_insert_defaults

# 需要导入模块: from pulp.server.db.model import TaskStatus [as 别名]
# 或者: from pulp.server.db.model.TaskStatus import save [as 别名]
    def test_save_insert_defaults(self):
        """
        Test the save method with default arguments when the object is not already in the database.
        """
        task_id = str(uuid4())
        worker_name = 'some_worker'
        tags = ['tag_1', 'tag_2']
        state = constants.CALL_RUNNING_STATE
        spawned_tasks = ['foo']
        error = {'error': 'some_error'}
        progress_report = {'what do we want?': 'progress!', 'when do we want it?': 'now!'}
        task_type = 'some.task'
        start_time = datetime.now()
        finish_time = start_time + timedelta(minutes=5)
        start_time = dateutils.format_iso8601_datetime(start_time)
        finish_time = dateutils.format_iso8601_datetime(finish_time)
        result = None
        ts = TaskStatus(
            task_id, worker_name, tags, state, spawned_tasks=spawned_tasks, error=error,
            progress_report=progress_report, task_type=task_type, start_time=start_time,
            finish_time=finish_time, result=result)

        # This should cause ts to be in the database
        ts.save()

        ts = TaskStatus.objects()
        # There should only be one TaskStatus in the db
        self.assertEqual(ts.count(), 1)
        ts = ts[0]
        # Make sure all the attributes are correct
        self.assertEqual(ts['task_id'], task_id)
        self.assertEqual(ts['worker_name'], worker_name)
        self.assertEqual(ts['tags'], tags)
        self.assertEqual(ts['state'], state)
        self.assertEqual(ts['error'], error)
        self.assertEqual(ts['spawned_tasks'], spawned_tasks)
        self.assertEqual(ts['progress_report'], progress_report)
        self.assertEqual(ts['task_type'], task_type)
        self.assertEqual(ts['start_time'], start_time)
        self.assertEqual(ts['finish_time'], finish_time)
        self.assertEqual(ts['result'], result)
        # These are always None
        self.assertEqual(ts['traceback'], None)
        self.assertEqual(ts['exception'], None)
开发者ID:maxamillion,项目名称:pulp,代码行数:46,代码来源:test_dispatch.py


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