|
| 1 | +# Google Cloud Tasks Pull Queue Samples |
| 2 | + |
| 3 | +[![Open in Cloud Shell][shell_img]][shell_link] |
| 4 | + |
| 5 | +[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png |
| 6 | +[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-tasks&page=editor&open_in_editor=samples/README.md |
| 7 | + |
| 8 | +Sample command-line program for interacting with the Google Cloud Tasks API |
| 9 | +using pull queues. |
| 10 | + |
| 11 | +Pull queues let you add tasks to a queue, then programatically remove and |
| 12 | +interact with them. Tasks can be added or processed in any environment, |
| 13 | +such as on Google App Engine or Google Compute Engine. |
| 14 | + |
| 15 | +`tasks.js` is a simple command-line program to demonstrate listing queues, |
| 16 | + creating tasks, and pulling and acknowledging tasks. |
| 17 | + |
| 18 | +## Before you begin |
| 19 | + |
| 20 | + 1. Follow the steps in the |
| 21 | +[Before you begin section][before] of the client |
| 22 | + library's README. |
| 23 | + |
| 24 | + 2. Install dependencies: |
| 25 | + |
| 26 | + With **npm**: |
| 27 | + |
| 28 | + npm install |
| 29 | + |
| 30 | + With **yarn**: |
| 31 | + |
| 32 | + yarn install |
| 33 | + |
| 34 | +[before]:../README.md#before-you-begin |
| 35 | + |
| 36 | +## Creating a queue |
| 37 | + |
| 38 | +To create a queue using the Cloud SDK, use the following gcloud command: |
| 39 | + |
| 40 | + gcloud alpha tasks queues create pull my-pull-queue |
| 41 | + |
| 42 | +## Running the Samples |
| 43 | + |
| 44 | +Set the environment variables: |
| 45 | + |
| 46 | +First, your project ID: |
| 47 | + |
| 48 | + export PROJECT_ID=my-project-id |
| 49 | + |
| 50 | +Then the queue ID, as specified at queue creation time. Queue IDs already |
| 51 | +created can be listed with `gcloud alpha tasks queues list`. |
| 52 | + |
| 53 | + export QUEUE_ID=my-pull-queue |
| 54 | + |
| 55 | +And finally the location ID, which can be discovered with |
| 56 | +`gcloud alpha tasks queues describe $QUEUE_ID`, with the location embedded in |
| 57 | +the "name" value (for instance, if the name is |
| 58 | +"projects/my-project/locations/us-central1/queues/my-pull-queue", then the |
| 59 | +location is "us-central1"). |
| 60 | + |
| 61 | + export LOCATION_ID=us-central1 |
| 62 | + |
| 63 | +Create a task for a queue: |
| 64 | + |
| 65 | + node tasks.js create $PROJECT_ID $LOCATION_ID $QUEUE_ID |
| 66 | + |
| 67 | +Pull a task: |
| 68 | + |
| 69 | + node tasks.js pull $PROJECT_ID $LOCATION_ID $QUEUE_ID |
| 70 | + |
| 71 | +Acknowledge task: |
| 72 | + |
| 73 | + node tasks.js acknowledge <task> |
| 74 | + |
| 75 | +* where task is the output from pull task, example: |
| 76 | +`'{"name":"projects/my-project-id/locations/us-central1/queues/my-queue/tasks/1234","scheduleTime":"2017-11-01T22:27: |
| 77 | + 53.628279Z"}'` |
0 commit comments