This sample demonstrates how to use the Google Cloud Tasks client library.
The api/TasksSample
project contains simple programs:
CreateHttpTask.cs
constructs a task with an HTTP target and pushes it to your queue.CreateTask.cs
constructs a task with an App Engine target and pushes it to your queue.
appengine
is a task handler. This example app that has an endpoint to
receive App Engine task attempts.
Before you can run or deploy the sample, you need to do the following:
- Enable the Cloud Tasks API in the Google Cloud Console.
- Set up Google Application Credentials.
To create a queue using the Cloud SDK, use the following gcloud command:
gcloud beta tasks queues create <QUEUE_NAME>
Set environment variables:
First, your project ID:
export GOOGLE_PROJECT_ID=my-project-id
Then the queue ID, as specified at queue creation time. Queue IDs already
created can be listed with gcloud beta tasks queues list
.
export GCP_QUEUE=<QUEUE_NAME>
And finally the location ID, which can be discovered with
gcloud beta tasks queues describe $GCP_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
Move into the Tasks Sample folder:
cd ../api/TasksSample
Install dependencies:
dotnet restore
Run the tests to run the samples:
dotnet test
Move into the App Engine folder:
cd ../../appengine
Deploy the App Engine app with gcloud
:
```psm1
PS > dotnet restore
PS > dotnet publish
PS > gcloud beta app deploy .\bin\Debug\netcoreapp2.1\publish\app.yaml
```
Verify the index page is serving:
gcloud app browse
The App Engine app serves as a target for the push requests. It has an
endpoint /log_payload
that reads the payload (i.e., the request body) of the
HTTP POST request and logs it. The log output can be viewed with:
gcloud app logs read