Cloud Tasks handlers can be run on any HTTP endpoint with an external IP address such as GKE, Compute Engine, or even an on-premises web server. Your tasks can be executed on any of these services in a reliable, configurable fashion.
This document demonstrates how to programmatically create HTTP target tasks using Cloud Tasks client libraries, and place them in Cloud Tasks queues. You can also create HTTP target tasks in the Google Cloud console, by using the Google Cloud CLI, or by sending a direct request to the Cloud Tasks API. For more information, see Create tasks.
For tasks that have HTTP targets (as opposed to explicit App Engine targets, which are less common), there are two ways to create tasks:
CreateTaskmethod: You must explicitly create a task object. Use this method if the tasks in your queue have different routing configurations. In this case, you specify routing at the task level and cannot use queue-level routing. This approach uses theCreateTaskmethod.BufferTaskmethod: Use this method if your queue is set up to buffer tasks in front of a service. The queue must have queue-level routing. This approach uses theBufferTaskmethod.
For guidance on how to choose between the two methods for creating HTTP tasks, see Choose your task creation method.
Create a task using the CreateTask method
This section discusses creating a task by constructing the task object. You use
the CreateTask method.
When you create a task using the CreateTask method, you explicitly create and
define the task object. You must specify the service and handler that process
the task.
Optionally, you can pass task-specific data along to the handler. You can also fine-tune the configuration for the task, like scheduling a time in the future when it should be executed or limiting the number of times you want the task to be retried if it fails (see Advanced configuration).
The following examples call the CreateTask method to create a task using the
Cloud Tasks client libraries.