From f080049b49cb599e751720790f272f1ebf11a209 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Fri, 3 Aug 2018 10:19:43 -0700 Subject: [PATCH 1/2] Remove tasks samples --- cloudtasks/README.md | 79 +------------- cloudtasks/package.json | 37 ------- cloudtasks/system-test/tasks.test.js | 64 ----------- cloudtasks/tasks.js | 153 --------------------------- 4 files changed, 4 insertions(+), 329 deletions(-) delete mode 100644 cloudtasks/package.json delete mode 100644 cloudtasks/system-test/tasks.test.js delete mode 100644 cloudtasks/tasks.js diff --git a/cloudtasks/README.md b/cloudtasks/README.md index fcd168440b..b9b1c614c9 100644 --- a/cloudtasks/README.md +++ b/cloudtasks/README.md @@ -1,76 +1,5 @@ -Google Cloud Platform logo +Samples for the [Google Cloud Tasks API Node.js Client][client] +have moved to [github.com/googleapis/nodejs-tasks/tree/master/samples/][samples]. -# Google Cloud Tasks API Node.js Samples - -The [Cloud Tasks API](https://cloud.google.com/cloud-tasks/docs) enables -developers to manage the execution of large numbers of distributed requests. - -## Table of Contents - -* [Setup](#setup) -* [Samples](#samples) - * [Tasks](#tasks) -* [Running the tests](#running-the-tests) - -## Setup - -1. Read [Prerequisites][prereq] and [How to run a sample][run] first. -1. Install dependencies: - - With **npm**: - - npm install - - With **yarn**: - - yarn install - -[prereq]: ../README.md#prerequisites -[run]: ../README.md#how-to-run-a-sample - -## Samples - -### Tasks - -View the [documentation][tasks_0_docs] or the [source code][tasks_0_code]. - -__Usage:__ `node tasks.js --help` - -``` -tasks.js - -Commands: - tasks.js create Create a task. - tasks.js pull Pull a task. - tasks.js acknowledge Acknowledge a task. - -Options: - --version Show version number [boolean] - --help Show help [boolean] - -Examples: - node tasks.js create my-project-id us-central1 my-queue - node tasks.js pull my-project-id us-central1 my-queue - node tasks.js acknowledge - '{"name":"projects/my-project-id/locations/us-central1/queues/my-queue/tasks/1234","scheduleTime":"2017-11-01T22:27: - 53.628279Z"}' - -For more information, see https://cloud.google.com/cloud-tasks/docs -``` - -[tasks_0_docs]: https://cloud.google.com/cloud-tasks/docs -[tasks_0_code]: tasks.js - -## Running the tests - -1. Set the **GCLOUD_PROJECT** and **GOOGLE_APPLICATION_CREDENTIALS** environment variables. - -1. Run the tests: - - With **npm**: - - npm test - - With **yarn**: - - yarn test +[client]: https://github.com/googleapis/nodejs-tasks +[samples]: https://github.com/googleapis/nodejs-tasks/tree/master/samples \ No newline at end of file diff --git a/cloudtasks/package.json b/cloudtasks/package.json deleted file mode 100644 index 5fd26dc7c9..0000000000 --- a/cloudtasks/package.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "name": "nodejs-docs-samples-cloudtasks", - "version": "0.0.0", - "license": "Apache-2.0", - "author": "Google Inc.", - "private": true, - "repository": "GoogleCloudPlatform/nodejs-docs-samples", - "engines": { - "node": ">=4.0.0" - }, - "scripts": { - "lint": "repo-tools lint", - "pretest": "npm run lint", - "system-test": "ava -T 3m --verbose --fail-fast system-test/*.test.js", - "test": "repo-tools test run --cmd npm -- run system-test" - }, - "dependencies": { - "googleapis": "29.0.0", - "yargs": "11.0.0" - }, - "devDependencies": { - "@google-cloud/nodejs-repo-tools": "2.2.1", - "ava": "0.25.0", - "semistandard": "^12.0.1" - }, - "cloud-repo-tools": { - "requiresKeyFile": true, - "requiresProjectId": true, - "test": { - "build": { - "requiredEnvVars": [ - "GCP_QUEUE" - ] - } - } - } -} diff --git a/cloudtasks/system-test/tasks.test.js b/cloudtasks/system-test/tasks.test.js deleted file mode 100644 index 6198d48538..0000000000 --- a/cloudtasks/system-test/tasks.test.js +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright 2017, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -const path = require(`path`); -const test = require(`ava`); -const tools = require(`@google-cloud/nodejs-repo-tools`); - -const { - runAsync -} = require(`@google-cloud/nodejs-repo-tools`); - -const PROJECT_ID = process.env.GCLOUD_PROJECT; -const QUEUE = process.env.GCP_QUEUE; -const cmd = `node tasks.js`; -const cwd = path.join(__dirname, `..`); - -test.before((t) => { - if (!QUEUE) { - t.fail(`You must set the GCP_QUEUE environment variable!`); - } -}); -test.before(tools.checkCredentials); - -let task; - -test.serial(`should create a task`, async (t) => { - const output = await runAsync(`${cmd} create ${PROJECT_ID} us-central1 "${QUEUE}"`, cwd); - t.true(output.includes('Created task')); -}); - -test.serial(`should pull a task`, async (t) => { - t.plan(0); - await tools.tryTest(async (assert) => { - const output = await runAsync(`${cmd} pull ${PROJECT_ID} us-central1 "${QUEUE}"`, cwd); - const matches = output.match(/^Pulled task ({.+})$/); - if (matches && matches.length > 1) { - task = matches[1]; - } - assert(output.includes(`Pulled task`)); - }).start(); -}); - -test.serial(`should acknowledge a task`, async (t) => { - if (task) { - const output = await runAsync(`${cmd} acknowledge '${task}'`, cwd); - t.true(output.includes(`Acknowledged task`)); - } else { - t.fail(`no task to acknowledge`); - } -}); diff --git a/cloudtasks/tasks.js b/cloudtasks/tasks.js deleted file mode 100644 index dfd67d34be..0000000000 --- a/cloudtasks/tasks.js +++ /dev/null @@ -1,153 +0,0 @@ -/** - * Copyright 2017, Google, Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict'; - -function createTask (project, location, queue) { - // [START cloud_tasks_create_task] - const {google} = require('googleapis'); - const cloudtasks = google.cloudtasks('v2beta2'); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const project = 'Project ID, e.g. my-project-id'; - // const location = 'Location of queue, e.g. us-central1'; - // const queue = 'Queue ID, e.g. queue-1'; - - return google.auth.getClient({ - scopes: ['https://www.googleapis.com/auth/cloud-platform'] - }) - .then(authClient => { - // Schedule the task for 2 minutes from now - const scheduleTime = new Date(); - scheduleTime.setUTCMinutes(scheduleTime.getUTCMinutes() + 2); - - const task = { - scheduleTime: scheduleTime, - pull_message: { - payload: Buffer.from('a message for the recipient').toString('base64') - } - }; - - const request = { - parent: `projects/${project}/locations/${location}/queues/${queue}`, - resource: { - task: task - }, - auth: authClient - }; - - return cloudtasks.projects.locations.queues.tasks.create(request); - }) - .then(response => { - console.log(`Created task ${response.data.name}.`); - console.log(JSON.stringify(response.data, null, 2)); - }) - .catch(console.error); - // [END cloud_tasks_create_task] -} - -function pullTask (project, location, queue) { - // [START cloud_tasks_pull_and_acknowledge_task] - const {google} = require('googleapis'); - const cloudtasks = google.cloudtasks('v2beta2'); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const project = 'Project ID, e.g. my-project-id'; - // const location = 'Location of queue, e.g. us-central1'; - // const queue = 'Queue ID, e.g. queue-1'; - - return google.auth.getClient({ - scopes: ['https://www.googleapis.com/auth/cloud-platform'] - }) - .then(authClient => { - const request = { - parent: `projects/${project}/locations/${location}/queues/${queue}`, - responseView: 'FULL', - pageSize: 1, - auth: authClient - }; - - return cloudtasks.projects.locations.queues.tasks.list(request); - }) - .then(response => { - const task = response.data.tasks[0]; - console.log('Pulled task %j', task); - }) - .catch(console.error); -} - -function acknowledgeTask (task) { - const {google} = require('googleapis'); - const cloudtasks = google.cloudtasks('v2beta2'); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const task = { - // name: 'projects/YOUR_PROJECT_ID/locations/us-central1/queues/YOUR_QUEUE_ID/tasks/YOUR_TASK_ID, - // scheduleTime: '2017-11-01T21:02:28.994Z' // TODO(developer): set this to your task's scheduled time - // }; - - return google.auth.getClient({ - scopes: ['https://www.googleapis.com/auth/cloud-platform'] - }) - .then(authClient => { - const request = { - name: task.name, - scheduleTime: task.scheduleTime, - auth: authClient - }; - - return cloudtasks.projects.locations.queues.tasks.acknowledge(request); - }) - .then(response => { - console.log(`Acknowledged task ${task.name}.`); - }) - .catch(console.error); - // [END cloud_tasks_pull_and_acknowledge_task] -} - -require(`yargs`) // eslint-disable-line - .demand(1) - .command( - `create `, - `Create a task.`, - {}, - (opts) => createTask(opts.project, opts.location, opts.queue) - ) - .command( - `pull `, - `Pull a task.`, - {}, - (opts) => pullTask(opts.project, opts.location, opts.queue) - ) - .command( - `acknowledge `, - `Acknowledge a task.`, - {}, - (opts) => acknowledgeTask(JSON.parse(opts.task)) - ) - .example(`node $0 create my-project-id us-central1 my-queue`) - .example(`node $0 pull my-project-id us-central1 my-queue`) - .example(`node $0 acknowledge '{"name":"projects/my-project-id/locations/us-central1/queues/my-queue/tasks/1234","scheduleTime":"2017-11-01T22:27:53.628279Z"}'`) - .wrap(120) - .recommendCommands() - .epilogue(`For more information, see https://cloud.google.com/cloud-tasks/docs`) - .help() - .strict().argv; From 26810fa8f9dcd3e461311086b9d03ba56ee3541a Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Fri, 3 Aug 2018 10:26:48 -0700 Subject: [PATCH 2/2] Delete cloudtasks job config --- .kokoro/cloudtasks.cfg | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 .kokoro/cloudtasks.cfg diff --git a/.kokoro/cloudtasks.cfg b/.kokoro/cloudtasks.cfg deleted file mode 100644 index bfcdd3b554..0000000000 --- a/.kokoro/cloudtasks.cfg +++ /dev/null @@ -1,19 +0,0 @@ -# Format: //devtools/kokoro/config/proto/build.proto - -# Set the folder in which the tests are run -env_vars: { - key: "PROJECT" - value: "cloudtasks" -} - -# Tell the trampoline which build file to use. -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/nodejs-docs-samples/.kokoro/build.sh" -} - -# Set the task queue to use -env_vars: { - key: "GCP_QUEUE" - value: "nodejs-test-queue-do-not-delete" -} \ No newline at end of file