-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: add queue create and delete samples (#142)
- Loading branch information
1 parent
d8032de
commit 9320185
Showing
6 changed files
with
137 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2018 Google LLC | ||
// | ||
// 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 | ||
// | ||
// https://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'; | ||
|
||
/** | ||
* Create a new Task Queue | ||
*/ | ||
async function createQueue( | ||
project = 'my-project-id', // Your GCP Project id | ||
queue = 'my-appengine-queue', // Name of the Queue to create | ||
location = 'us-central1' // The GCP region in which to create the queue | ||
) { | ||
// Imports the Google Cloud Tasks library. | ||
const cloudTasks = require('@google-cloud/tasks'); | ||
|
||
// Instantiates a client. | ||
const client = new cloudTasks.CloudTasksClient(); | ||
|
||
// Send create queue request. | ||
const [response] = await client.createQueue({ | ||
// The fully qualified path to the location where the queue is created | ||
parent: client.locationPath(project, location), | ||
queue: { | ||
// The fully qualified path to the queue | ||
name: client.queuePath(project, location, queue), | ||
appEngineHttpQueue: { | ||
appEngineRoutingOverride: { | ||
// The App Engine service that will receive the tasks. | ||
service: 'default', | ||
}, | ||
}, | ||
}, | ||
}); | ||
console.log(`Created queue ${response.name}`); | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
createQueue(...args).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2018 Google LLC | ||
// | ||
// 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 | ||
// | ||
// https://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'; | ||
|
||
/** | ||
* Delete a given Queue | ||
*/ | ||
async function deleteQueue( | ||
project = 'my-project-id', // Your GCP Project id | ||
queue = 'my-appengine-queue', // Name of the Queue to delete | ||
location = 'us-central1' // The GCP region in which to delete the queue | ||
) { | ||
// Imports the Google Cloud Tasks library. | ||
const cloudTasks = require('@google-cloud/tasks'); | ||
|
||
// Instantiates a client. | ||
const client = new cloudTasks.CloudTasksClient(); | ||
|
||
// Get the fully qualified path to the queue | ||
const name = client.queuePath(project, location, queue); | ||
|
||
// Send delete queue request. | ||
await client.deleteQueue({name}); | ||
console.log(`Deleted queue '${queue}'.`); | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
deleteQueue(...args).catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,3 @@ env: | |
mocha: true | ||
rules: | ||
node/no-unpublished-require: off | ||
no-empty: off |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2018 Google LLC | ||
// | ||
// 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 | ||
// | ||
// https://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 assert = require('assert'); | ||
const execa = require('execa'); | ||
const uuid = require('uuid'); | ||
|
||
const PROJECT_ID = process.env.GCLOUD_PROJECT; | ||
const queueName = `gcloud-${uuid.v4().split('-')[0]}`; | ||
const cwd = path.join(__dirname, '..'); | ||
const exec = cmd => execa.shell(cmd, {cwd}); | ||
|
||
describe('Cloud Task Sample Tests', () => { | ||
it('should create a queue', async () => { | ||
const {stdout} = await exec(`node createQueue ${PROJECT_ID} ${queueName}`); | ||
assert.ok(stdout.includes('Created queue')); | ||
}); | ||
|
||
it('should create a task', async () => { | ||
const {stdout} = await exec( | ||
`node createTask --project=${PROJECT_ID} --location=us-central1 --queue=${queueName}` | ||
); | ||
assert.ok(stdout.includes('Created task')); | ||
}); | ||
|
||
it('should delete a queue', async () => { | ||
const {stdout} = await exec(`node deleteQueue ${PROJECT_ID} ${queueName}`); | ||
assert.ok(stdout.includes('Deleted queue')); | ||
}); | ||
}); |