Ejemplo n.º 1
0
def _make_task_bytes(args):
  """Returns a serialized Task proto.

  Args:
    args: Proto message to put in the Task's args field.
  """
  task = task_pb2.Task()
  task.args.Pack(args)
  return task.SerializeToString()
Ejemplo n.º 2
0
 def test_publish_is_called_by(self, request_by_args):
   args = test_task_pb2.FooTaskArgs()
   task = task_pb2.Task()
   task.args.Pack(args)
   publish_future = mock.Mock()
   self._client.publish.return_value = publish_future
   if request_by_args:
     returned_future = self._requestor.request('kumquat', args)
   else:
     returned_future = self._requestor.request_task('kumquat', task)
   self.assertIs(publish_future, returned_future)
   self._client.publish.assert_called_once_with('kumquat',
                                                task.SerializeToString())
Ejemplo n.º 3
0
    def request(self, topic: Text, args: message.Message) -> futures.Future:
        """Constructs a Task proto and sends it to background workers.

    Most callers should use this method unless they have a reason to construct
    the Task proto themselves.

    Args:
      topic: Resource name of the pubsub topic to send the request to.
      args: Task arguments. The type of this proto determines which task to
        call.

    Returns:
      Future for the request. The future will complete when the request is sent,
      not when the task is completed.
    """
        task = task_pb2.Task()
        task.args.Pack(args)
        return self.request_task(topic, task)