Skip to content

Commit c26a94f

Browse files
feat: add v2 of the tasks API (#192)
1 parent 4494037 commit c26a94f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

cloud-tasks/listQueues.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
async function listQueues(
18+
project = 'my-project-id', // Your GCP Project id
19+
location = 'us-central1' // The GCP region to search for queues
20+
) {
21+
// Imports the Google Cloud Tasks library.
22+
const cloudTasks = require('@google-cloud/tasks');
23+
24+
// Instantiates a client.
25+
const client = new cloudTasks.CloudTasksClient();
26+
27+
// Get the fully qualified path to the region
28+
const parent = client.locationPath(project, location);
29+
30+
// list all fo the queues
31+
const [queues] = await client.listQueues({parent});
32+
33+
if (queues.length > 0) {
34+
console.log('Queues:');
35+
queues.forEach(queue => {
36+
console.log(` ${queue.name}`);
37+
});
38+
} else {
39+
console.log('No queues found!');
40+
}
41+
}
42+
43+
const args = process.argv.slice(2);
44+
listQueues(...args).catch(console.error);

0 commit comments

Comments
 (0)