Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
 
 

README.md

Outline

Google Cloud Tasks Samples

Open in Cloud Shell

This sample demonstrates how to use the Cloud Tasks client library.

create_http_task.py is a simple command-line program to create tasks to be pushed to an URL endpoint.

create_http_task_with_token.py is a simple command-line program to create tasks to be pushed to an URL endpoint with authorization header.

Prerequisites to run locally:

Please refer to Setting Up a Python Development Environment.

Authentication

To set up authentication, please refer to our authentication getting started guide.

Creating a queue

To create a queue (named my-queue) using the Cloud SDK, use the following gcloud command:

gcloud tasks queues create my-queue

Run the Sample Using the Command Line

Set environment variables:

First, your project ID:

export PROJECT_ID=my-project-id

Then the queue ID, as specified at queue creation time. Queue IDs already created can be listed with gcloud tasks queues list.

export QUEUE_ID=my-queue

And finally the location ID, which can be discovered with gcloud tasks queues describe my-queue, with the location embedded in the "name" value (for instance, if the name is "projects/my-project/locations/us-central1/queues/my-queue", then the location is "us-central1").

export LOCATION_ID=us-central1

Creating Tasks with HTTP Targets

Set an environment variable for the endpoint to your task handler. This is an example url:

export URL=https://example.com/task_handler

Running the sample will create a task and send the task to the specific URL endpoint, with a payload specified:

python create_http_task.py --project=$PROJECT_ID --queue=$QUEUE_ID --location=$LOCATION_ID --url=$URL --payload=hello
Morty Proxy This is a proxified and sanitized view of the page, visit original site.