Creates a task and adds it to a queue.

        Tasks cannot be updated after creation; there is no UpdateTask command.

        -  For ``App Engine queues``, the maximum task size is 100KB.

        Example:
            >>> from google.cloud import tasks_v2
            >>>
            >>> client = tasks_v2.CloudTasksClient()
            >>>
            >>> parent = client.queue_path('[PROJECT]', '[LOCATION]', '[QUEUE]')
            >>>
            >>> # TODO: Initialize `task`:
            >>> task = {}
            >>>
            >>> response = client.create_task(parent, task)

        Args:
            parent (str): Required.

                The queue name. For example:
                ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID``

                The queue must already exist.
            task (Union[dict, ~google.cloud.tasks_v2.types.Task]): Required.

                The task to add.

                Task names have the following format:
                ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID``.
                The user can optionally specify a task ``name``. If a name is not
                specified then the system will generate a random unique task id, which
                will be set in the task returned in the ``response``.

                If ``schedule_time`` is not set or is in the past then Cloud Tasks will
                set it to the current time.

                Task De-duplication:

                Explicitly specifying a task ID enables task de-duplication. If a task's
                ID is identical to that of an existing task or a task that was deleted
                or executed recently then the call will fail with ``ALREADY_EXISTS``. If
                the task's queue was created using Cloud Tasks, then another task with
                the same name can't be created for ~1hour after the original task was
                deleted or executed. If the task's queue was created using queue.yaml or
                queue.xml, then another task with the same name can't be created for
                ~9days after the original task was deleted or executed.

                Because there is an extra lookup cost to identify duplicate task names,
                these ``CreateTask`` calls have significantly increased latency. Using
                hashed strings for the task id or for the prefix of the task id is
                recommended. Choosing task ids that are sequential or have sequential
                prefixes, for example using a timestamp, causes an increase in latency
                and error rates in all task commands. The infrastructure relies on an
                approximately uniform distribution of task ids to store and serve tasks
                efficiently.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.tasks_v2.types.Task`
            response_view (~google.cloud.tasks_v2.types.View): The response\_view specifies which subset of the ``Task`` will be
                returned.

                By default response\_view is ``BASIC``; not all information is retrieved
                by default because some data, such as payloads, might be desirable to
                return only when needed because of its large size or because of the
                sensitivity of data that it contains.

                Authorization for ``FULL`` requires ``cloudtasks.tasks.fullView``
                `Google IAM <https://cloud.google.com/iam/>`___ permission on the
                ``Task`` resource.
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will not
                be retried.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Returns:
            A :class:`~google.cloud.tasks_v2.types.Task` instance.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.

def create_task(
        self,
        parent,
        task,
        response_view=None,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Creates a task and adds it to a queue.

        Tasks cannot be updated after creation; there is no UpdateTask command.

        -  For ``App Engine queues``, the maximum task size is 100KB.

        Example:
            >>> from google.cloud import tasks_v2
            >>>
            >>> client = tasks_v2.CloudTasksClient()
            >>>
            >>> parent = client.queue_path('[PROJECT]', '[LOCATION]', '[QUEUE]')
            >>>
            >>> # TODO: Initialize `task`:
            >>> task = {}
            >>>
            >>> response = client.create_task(parent, task)

        Args:
            parent (str): Required.

                The queue name. For example:
                ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID``

                The queue must already exist.
            task (Union[dict, ~google.cloud.tasks_v2.types.Task]): Required.

                The task to add.

                Task names have the following format:
                ``projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID``.
                The user can optionally specify a task ``name``. If a name is not
                specified then the system will generate a random unique task id, which
                will be set in the task returned in the ``response``.

                If ``schedule_time`` is not set or is in the past then Cloud Tasks will
                set it to the current time.

                Task De-duplication:

                Explicitly specifying a task ID enables task de-duplication. If a task's
                ID is identical to that of an existing task or a task that was deleted
                or executed recently then the call will fail with ``ALREADY_EXISTS``. If
                the task's queue was created using Cloud Tasks, then another task with
                the same name can't be created for ~1hour after the original task was
                deleted or executed. If the task's queue was created using queue.yaml or
                queue.xml, then another task with the same name can't be created for
                ~9days after the original task was deleted or executed.

                Because there is an extra lookup cost to identify duplicate task names,
                these ``CreateTask`` calls have significantly increased latency. Using
                hashed strings for the task id or for the prefix of the task id is
                recommended. Choosing task ids that are sequential or have sequential
                prefixes, for example using a timestamp, causes an increase in latency
                and error rates in all task commands. The infrastructure relies on an
                approximately uniform distribution of task ids to store and serve tasks
                efficiently.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.tasks_v2.types.Task`
            response_view (~google.cloud.tasks_v2.types.View): The response\_view specifies which subset of the ``Task`` will be
                returned.

                By default response\_view is ``BASIC``; not all information is retrieved
                by default because some data, such as payloads, might be desirable to
                return only when needed because of its large size or because of the
                sensitivity of data that it contains.

                Authorization for ``FULL`` requires ``cloudtasks.tasks.fullView``
                `Google IAM <https://cloud.google.com/iam/>`___ permission on the
                ``Task`` resource.
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will not
                be retried.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Returns:
            A :class:`~google.cloud.tasks_v2.types.Task` instance.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        # Wrap the transport method to add retry and timeout logic.
        if "create_task" not in self._inner_api_calls:
            self._inner_api_calls[
                "create_task"
            ] = google.api_core.gapic_v1.method.wrap_method(
                self.transport.create_task,
                default_retry=self._method_configs["CreateTask"].retry,
                default_timeout=self._method_configs["CreateTask"].timeout,
                client_info=self._client_info,
            )

        request = cloudtasks_pb2.CreateTaskRequest(
            parent=parent, task=task, response_view=response_view
        )
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        try:
            routing_header = [("parent", parent)]
        except AttributeError:
            pass
        else:
            routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
                routing_header
            )
            metadata.append(routing_metadata)

        return self._inner_api_calls["create_task"](
            request, retry=retry, timeout=timeout, metadata=metadata
        )