def GetFilteredTasks(self, url='', name='', queue_names=()):
        """Delegating TaskQueueServiceStub.get_filtered_tasks.

    Args:
      url: A string URL that represents the URL all returned tasks point at.
      name: The string name of all returned tasks.
      queue_names: A string queue_name, or a list of string queue names to
        retrieve tasks from. If left blank this will get default to all
        queues available.

    Returns:
      A list of taskqueue.Task objects.
    """
        request = taskqueue_stub_service_pb.GetFilteredTasksRequest()
        request.set_url(url)
        request.set_name(name)

        if isinstance(queue_names, basestring):
            queue_names = [queue_names]
        map(request.add_queue_names, queue_names)
        response = taskqueue_stub_service_pb.GetFilteredTasksResponse()
        self.MakeSyncCall('taskqueue', 'GetFilteredTasks', request, response)

        res = []
        for i, eta_delta in enumerate(response.eta_delta_list()):

            task_dict = taskqueue_stub.QueryTasksResponseToDict(
                '',
                response.query_tasks_response().task(i),
                datetime.datetime.now())
            task_dict['eta_delta'] = eta_delta
            res.append(taskqueue_stub.ConvertTaskDictToTaskObject(task_dict))
        return res
Exemplo n.º 2
0
  def GetTasks(self, queue_name):
    """Delegating TaskQueueServiceStub.GetTasks.

    Args:
      queue_name: String, the name of the queue to return tasks for.

    Returns:
      A list of dictionaries, where each dictionary contains one task's
        attributes.
    """
    request = taskqueue_stub_service_pb.GetFilteredTasksRequest()
    request.add_queue_names(queue_name)
    response = taskqueue_stub_service_pb.GetFilteredTasksResponse()
    self.MakeSyncCall('taskqueue', 'GetFilteredTasks', request, response)
    res = []
    for i, eta_delta in enumerate(response.eta_delta_list()):



      task_dict = taskqueue_stub.QueryTasksResponseToDict(
          queue_name, response.query_tasks_response().task(i),


          datetime.datetime.now())
      task_dict['eta_delta'] = eta_delta
      res.append(task_dict)
    return res
Exemplo n.º 3
0
def run_queue_enable_retries(queue_service,
                             queue_name,
                             non_furious_url_prefixes=None,
                             non_furious_handler=None):
    """
    Run the tasks in a queue with AE task retries and retry limit.

    Ignores delays to start tasks.
    Only deletes the task if task doesn't raise an exception or it has
    reached the max number of retries.
    Uses internal App Engine SDK calls, so run_queue() is be more
    stable if retries are not important.

    :param queue_service: :class: `taskqueue_stub.TaskQueueServiceStub`
    :param queue_name: :class: `str`
    :param non_furious_url_prefixes: :class: `list` of url prefixes that the
     furious task runner will run.
    :param non_furious_handler: :class: `func` handler for non furious tasks to
     run within.
    """

    queue = queue_service._GetGroup().GetQueue(queue_name)
    task_responses = [
        task_response for (_, _, task_response) in queue._sorted_by_eta
    ]

    num_processed = 0

    for task_response in task_responses:

        now = datetime.datetime.utcnow()
        task_dict = taskqueue_stub.QueryTasksResponseToDict(
            queue_name, task_response, now)

        success = _execute_wrapped_task(task_dict, queue_service, queue_name,
                                        non_furious_url_prefixes,
                                        non_furious_handler)

        if success:
            queue_service.DeleteTask(queue_name, task_dict.get('name'))
        else:
            _retry_or_delete(task_dict, task_response, queue, queue_service,
                             queue_name)

        num_processed += 1

    return num_processed
Exemplo n.º 4
0
    def _get_tasks(queue_name,
                   count,
                   start_task_name=None,
                   start_eta_usec=None):
        request = taskqueue_service_pb.TaskQueueQueryTasksRequest()
        request.set_queue_name(queue_name)
        request.set_max_rows(count)
        if start_task_name is not None:
            request.set_start_task_name(start_task_name)
        if start_eta_usec is not None:
            request.set_start_eta_usec(start_eta_usec)

        response = taskqueue_service_pb.TaskQueueQueryTasksResponse()
        apiproxy_stub_map.MakeSyncCall('taskqueue', 'QueryTasks', request,
                                       response)

        now = datetime.datetime.utcnow()
        for task in response.task_list():
            # Nothing is done with the body so save some memory and CPU by removing
            # it.
            task.set_body('')
            yield taskqueue_stub.QueryTasksResponseToDict(
                queue_name, task, now)