Skip to content

Commit 458165e

Browse files
committed
Add AppEngine Cloud Tasks region tags.
1 parent c61dd1c commit 458165e

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

appengine/cloudtasks/createTask.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,11 @@
1818
const google = require('googleapis');
1919
const cloudtasks = google.cloudtasks('v2beta2');
2020

21-
function authorize (callback) {
22-
google.auth.getApplicationDefault(function (err, authClient) {
23-
if (err) {
24-
console.error('authentication failed: ', err);
25-
return;
26-
}
27-
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
28-
var scopes = ['https://www.googleapis.com/auth/cloud-platform'];
29-
authClient = authClient.createScoped(scopes);
30-
}
31-
callback(authClient);
32-
});
33-
}
34-
3521
/**
3622
* Create a task for a given queue with an arbitrary payload.
3723
*/
3824
function createTask (project, location, queue, options) {
25+
// [START cloud_tasks_appengine_create_task]
3926
authorize((authClient) => {
4027
const task = {
4128
app_engine_http_request: {
@@ -72,6 +59,21 @@ function createTask (project, location, queue, options) {
7259
console.log(JSON.stringify(response, null, 2));
7360
});
7461
});
62+
63+
function authorize (callback) {
64+
google.auth.getApplicationDefault(function (err, authClient) {
65+
if (err) {
66+
console.error('authentication failed: ', err);
67+
return;
68+
}
69+
if (authClient.createScopedRequired && authClient.createScopedRequired()) {
70+
var scopes = ['https://www.googleapis.com/auth/cloud-platform'];
71+
authClient = authClient.createScoped(scopes);
72+
}
73+
callback(authClient);
74+
});
75+
}
76+
// [END cloud_tasks_appengine_create_task]
7577
}
7678

7779
const cli = require(`yargs`)

appengine/cloudtasks/server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
'use strict';
1717

18+
// [START cloud_tasks_appengine_quickstart]
1819
const bodyParser = require('body-parser');
1920
const express = require('express');
2021

@@ -45,3 +46,4 @@ app.listen(process.env.PORT || 8080, () => {
4546
console.log(`App listening on port ${PORT}`);
4647
console.log('Press Ctrl+C to quit.');
4748
});
49+
// [END cloud_tasks_appengine_quickstart]

0 commit comments

Comments
 (0)