예제 #1
0
    def __AddTasks(self, tasks, transactional):
        """Internal implementation of .add() where tasks must be a list."""

        if len(tasks) > MAX_TASKS_PER_ADD:
            raise TooManyTasksError(
                'No more than %d tasks can be added in a single add call' %
                MAX_TASKS_PER_ADD)

        request = taskqueue_service_pb.TaskQueueBulkAddRequest()
        response = taskqueue_service_pb.TaskQueueBulkAddResponse()

        task_names = set()
        for task in tasks:
            if task.name:
                if task.name in task_names:
                    raise DuplicateTaskNameError(
                        'The task name %r is used more than once in the request'
                        % task.name)
                task_names.add(task.name)

            self.__FillAddRequest(task, request.add_add_request(),
                                  transactional)

        try:
            apiproxy_stub_map.MakeSyncCall('taskqueue', 'BulkAdd', request,
                                           response)
        except apiproxy_errors.ApplicationError, e:
            raise self.__TranslateError(e.application_error, e.error_detail)
예제 #2
0
    def __AddTasks(self, tasks, transactional):
        """Internal implementation of .add() where tasks must be a list."""

        if len(tasks) > MAX_TASKS_PER_ADD:
            raise TooManyTasksError(
                'No more than %d tasks can be added in a single add call' %
                MAX_TASKS_PER_ADD)

        request = taskqueue_service_pb.TaskQueueBulkAddRequest()
        response = taskqueue_service_pb.TaskQueueBulkAddResponse()

        task_names = set()
        for task in tasks:
            if task.name:
                if task.name in task_names:
                    raise DuplicateTaskNameError(
                        'The task name %r is used more than once in the request'
                        % task.name)
                task_names.add(task.name)

            self.__FillAddRequest(task, request.add_add_request(),
                                  transactional)

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

        assert response.taskresult_size() == len(tasks), (
            'expected %d results from BulkAdd(), got %d' %
            (len(tasks), response.taskresult_size()))

        exception = None
        for task, task_result in zip(tasks, response.taskresult_list()):
            if task_result.result(
            ) == taskqueue_service_pb.TaskQueueServiceError.OK:
                if task_result.has_chosen_task_name():
                    task._Task__name = task_result.chosen_task_name()
                task._Task__enqueued = True
            elif (task_result.result() ==
                  taskqueue_service_pb.TaskQueueServiceError.SKIPPED):
                pass
            elif exception is None:
                exception = self.__TranslateError(task_result.result())

        if exception is not None:
            raise exception

        return tasks
    def _Dynamic_Add(self, request, response):
        bulk_request = taskqueue_service_pb.TaskQueueBulkAddRequest()
        bulk_response = taskqueue_service_pb.TaskQueueBulkAddResponse()

        bulk_request.add_add_request().CopyFrom(request)
        self._Dynamic_BulkAdd(bulk_request, bulk_response)

        assert bulk_response.taskresult_size() == 1
        result = bulk_response.taskresult(0).result()

        if result != taskqueue_service_pb.TaskQueueServiceError.OK:
            raise apiproxy_errors.ApplicationError(result)
        elif bulk_response.taskresult(0).has_chosen_task_name():
            response.set_chosen_task_name(
                bulk_response.taskresult(0).chosen_task_name())