示例#1
0
    def SubmitHostEvents(self, request):
        """Submit a bundle of cluster host events for processing.

    Args:
      request: a HostEventList
    Returns:
      a VoidMessage
    """
        # Convert the request message to json for the taskqueue payload
        encoded_message = protojson.encode_message(request)  # pytype: disable=module-attr
        json_message = json.loads(encoded_message)
        host_events = json_message.get("host_events")
        if not host_events:
            raise endpoints.BadRequestException("Request has no host_events.")
        logging.info(
            "Submitting host event message with size %d and %d events",
            len(encoded_message), len(host_events))
        for event_chunk in chunks(host_events, CHUNK_SIZE):
            logging.info("Queuing host event chunk of size %d",
                         len(event_chunk))
            task_scheduler.AddCallableTask(
                self._ProcessHostEventWithNDB,
                event_chunk,
                _queue=host_event.HOST_EVENT_QUEUE_NDB,
                _target="%s.%s" %
                (common.GetServiceVersion(), common.GetServiceName()))
        logging.debug("Submitted host event message.")
        return message_types.VoidMessage()
def NotifyPendingRequestStateChanges():
    """Notify all states that have the notify_test_status flag set."""
    keys = (datastore_entities.Request.query(
        namespace=common.NAMESPACE).filter(
            datastore_entities.Request.notify_state_change == True).fetch(
                keys_only=True))
    for k in keys:
        task_scheduler.AddCallableTask(
            NotifyRequestState,
            request_id=k.id(),
            _queue=NOTIFICATION_TASK_QUEUE,
            _target='%s.%s' %
            (common.GetServiceVersion(), common.GetServiceName()))
    def testAddCallableTask(self):
        task_scheduler.AddCallableTask(Callable, 123, foo=bytearray(100))

        self.mock_add.assert_called_once_with(
            queue_name=task_scheduler.DEFAULT_CALLABLE_TASK_QUEUE,
            payload=mock.ANY,
            target=None,
            task_name=None,
            eta=None)
        payload = self.mock_add.call_args[1]['payload']
        # Small payload is executed directly
        self.assertEqual(Callable, pickle.loads(payload)[0])

        task_scheduler.RunCallableTask(payload)
        self.assertEqual(mock.call(123, foo=bytearray(100)),
                         _object.last_callable_call)
    def testAddCallableTask_withLargePayload(self):
        task_scheduler.AddCallableTask(Callable,
                                       123,
                                       foo=bytearray(100 * 1024))

        self.mock_add.assert_called_once_with(
            queue_name=task_scheduler.DEFAULT_CALLABLE_TASK_QUEUE,
            payload=mock.ANY,
            target=None,
            task_name=None,
            eta=None)
        payload = self.mock_add.call_args[1]['payload']
        # Large payload is stored in datastore
        self.assertEqual(task_scheduler._RunCallableTaskFromDatastore,
                         pickle.loads(payload)[0])

        task_scheduler.RunCallableTask(payload)
        self.assertEqual(mock.call(123, foo=bytearray(100 * 1024)),
                         _object.last_callable_call)
 def Func():
     task_scheduler.AddCallableTask(Callable,
                                    123,
                                    foo=bytearray(100 * 1024))
     raise ValueError()