예제 #1
0
    def query_and_own_tasks(self, app_id, http_data):
        """ Lease pull queue tasks.

    Args:
      app_id: The application ID.
      http_data: The payload containing the protocol buffer request.
    Returns:
      A tuple of a encoded response, error code, and error detail.
    """
        request = taskqueue_service_pb.TaskQueueQueryAndOwnTasksRequest(
            http_data)
        response = taskqueue_service_pb.TaskQueueQueryAndOwnTasksResponse()

        queue = self.get_queue(app_id, request.queue_name())
        tag = None
        if request.has_tag():
            tag = request.tag()

        try:
            tasks = queue.lease_tasks(request.max_tasks(),
                                      request.lease_seconds(),
                                      group_by_tag=request.group_by_tag(),
                                      tag=tag)
        except TransientError as lease_error:
            pb_error = taskqueue_service_pb.TaskQueueServiceError.TRANSIENT_ERROR
            return response.Encode(), pb_error, str(lease_error)

        for task in tasks:
            task_pb = response.add_task()
            task_pb.MergeFrom(task.encode_lease_pb())

        return response.Encode(), 0, ""
예제 #2
0
    def query_and_own_tasks(self, app_id, http_data):
        """ 

    Args:
      app_id: The application ID.
      http_data: The payload containing the protocol buffer request.
    Returns:
      A tuple of a encoded response, error code, and error detail.
    """
        # TODO implement.
        request = taskqueue_service_pb.TaskQueueQueryAndOwnTasksRequest(
            http_data)
        response = taskqueue_service_pb.TaskQueueQueryAndOwnTasksResponse()
        return (response.Encode(), 0, "")
  def lease_tasks(self, lease_seconds, max_tasks):
    """Leases a number of tasks from the Queue for a period of time.

    This method can only be performed on a pull Queue. Any non-pull tasks in
    the pull Queue will be converted into pull tasks when being leased. If
    fewer than max_tasks are available, all available tasks will be returned.
    The lease_tasks method supports leasing at most 1000 tasks for no longer
    than a week in a single call.

    Args:
      lease_seconds: Number of seconds to lease the tasks.
      max_tasks: Max number of tasks to lease from the pull Queue.

    Returns:
      A list of tasks leased from the Queue.

    Raises:
      InvalidLeaseTimeError: if lease_seconds is not a valid float or integer
        number or is outside the valid range.
      InvalidMaxTasksError: if max_tasks is not a valid integer or is outside
        the valid range.
      InvalidQueueModeError: if invoked on a queue that is not in pull mode.
      Error-subclass on application errors.
    """

    if not isinstance(lease_seconds, (float, int, long)):
      raise TypeError(
          'lease_seconds must be a float or an integer')
    lease_seconds = float(lease_seconds)

    if not isinstance(max_tasks, (int, long)):
      raise TypeError(
          'max_tasks must be an integer')

    if lease_seconds < 0.0:
      raise InvalidLeaseTimeError(
          'lease_seconds must not be negative')
    if lease_seconds > MAX_LEASE_SECONDS:
      raise InvalidLeaseTimeError(
          'Lease time must not be greater than %d seconds' %
          MAX_LEASE_SECONDS)
    if max_tasks <= 0:
      raise InvalidMaxTasksError(
          'Negative or zero tasks requested')
    if max_tasks > MAX_TASKS_PER_LEASE:
      raise InvalidMaxTasksError(
          'Only %d tasks can be leased at once' %
          MAX_TASKS_PER_LEASE)

    request = taskqueue_service_pb.TaskQueueQueryAndOwnTasksRequest()
    response = taskqueue_service_pb.TaskQueueQueryAndOwnTasksResponse()

    request.set_queue_name(self.__name)
    request.set_lease_seconds(lease_seconds)
    request.set_max_tasks(max_tasks)

    try:
      apiproxy_stub_map.MakeSyncCall('taskqueue',
                                     'QueryAndOwnTasks',
                                     request,
                                     response)
    except apiproxy_errors.ApplicationError, e:
      raise self.__TranslateError(e.application_error, e.error_detail)