Skip to content

Commit b5f86b2

Browse files
averikitschJustinBeckwith
authored andcommitted
docs(samples): Update metadata and arguments (#242)
1 parent f615737 commit b5f86b2

File tree

5 files changed

+44
-28
lines changed

5 files changed

+44
-28
lines changed

cloud-tasks/createHttpTask.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@
1818
// sample-metadata:
1919
// title: Cloud Tasks Create HTTP Target
2020
// description: Create Cloud Tasks with a HTTP Target
21+
// usage: node createHttpTask.js <projectId> <queueName> <location> <url> <payload> <delayInSeconds>
2122

2223
/**
2324
* Create a task with an HTTP target for a given queue with an arbitrary payload.
2425
*/
2526
async function createHttpTask(
26-
project,
27-
location,
28-
queue,
29-
url,
30-
payload,
31-
inSeconds
27+
project = 'my-project-id', // Your GCP Project id
28+
queue = 'my-appengine-queue', // Name of your Queue
29+
location = 'us-central1', // The GCP region of your queue
30+
url = 'https://example.com/taskhandler', // The full url path that the request will be sent to
31+
payload = 'Hello, World!', // The task HTTP request body
32+
inSeconds = 0 // Delay in task execution
3233
) {
3334
// [START cloud_tasks_create_http_task]
3435
// Imports the Google Cloud Tasks library.
@@ -41,16 +42,16 @@ async function createHttpTask(
4142
// const project = 'my-project-id';
4243
// const queue = 'my-queue';
4344
// const location = 'us-central1';
44-
// const url = 'https://example.com/taskhandler'
45-
// const payload = 'hello';
45+
// const url = 'https://example.com/taskhandler';
46+
// const payload = 'Hello, World!';
4647

4748
// Construct the fully qualified queue name.
4849
const parent = client.queuePath(project, location, queue);
4950

5051
const task = {
5152
httpRequest: {
5253
httpMethod: 'POST',
53-
url, //The full url path that the request will be sent to.
54+
url,
5455
},
5556
};
5657

@@ -59,6 +60,7 @@ async function createHttpTask(
5960
}
6061

6162
if (inSeconds) {
63+
// The time when the task is scheduled to be attempted.
6264
task.scheduleTime = {
6365
seconds: inSeconds + Date.now() / 1000,
6466
};

cloud-tasks/createHttpTaskWithToken.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@
1818
// sample-metadata:
1919
// title: Cloud Tasks Create HTTP Target with Token
2020
// description: Create Cloud Tasks with a HTTP Target with Token
21+
// usage: node createHttpTaskWithToken.js <projectId> <queueName> <location> <url> <serviceAccountEmail> <payload> <delayInSeconds>
2122

2223
/**
2324
* Create a task with an HTTP target for a given queue with an arbitrary payload.
2425
*/
2526
async function createHttpTaskWithToken(
26-
project,
27-
location,
28-
queue,
29-
url,
30-
email,
31-
payload,
32-
inSeconds
27+
project = 'my-project-id', // Your GCP Project id
28+
queue = 'my-queue', // Name of your Queue
29+
location = 'us-central1', // The GCP region of your queue
30+
url = 'https://example.com/taskhandler', // The full url path that the request will be sent to
31+
email = 'client@<project-id>.iam.gserviceaccount.com', // Cloud IAM service account
32+
payload = 'Hello, World!', // The task HTTP request body
33+
inSeconds = 0 // Delay in task execution
3334
) {
3435
// [START cloud_tasks_create_http_task_with_token]
3536
// Imports the Google Cloud Tasks library.
@@ -42,17 +43,17 @@ async function createHttpTaskWithToken(
4243
// const project = 'my-project-id';
4344
// const queue = 'my-queue';
4445
// const location = 'us-central1';
45-
// const url = 'https://example.com/taskhandler'
46-
// const email = 'client@<project-id>.iam.gserviceaccount.com'
47-
// const payload = 'hello';
46+
// const url = 'https://example.com/taskhandler';
47+
// email = 'client@<project-id>.iam.gserviceaccount.com';
48+
// const payload = 'Hello, World!';
4849

4950
// Construct the fully qualified queue name.
5051
const parent = client.queuePath(project, location, queue);
5152

5253
const task = {
5354
httpRequest: {
5455
httpMethod: 'POST',
55-
url, //The full url path that the request will be sent to.
56+
url,
5657
oidcToken: {
5758
serviceAccountEmail: email,
5859
},
@@ -64,6 +65,7 @@ async function createHttpTaskWithToken(
6465
}
6566

6667
if (inSeconds) {
68+
// The time when the task is scheduled to be attempted.
6769
task.scheduleTime = {
6870
seconds: inSeconds + Date.now() / 1000,
6971
};

cloud-tasks/createTask.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,21 @@
1515

1616
'use strict';
1717

18+
// sample-metadata:
19+
// title: Cloud Tasks Create App Engine Target
20+
// description: Create Cloud Tasks with a Google App Engine Target
21+
// usage: node createTask.js <projectId> <queueName> <location> <payload> <delayInSeconds>
22+
1823
/**
1924
* Create a task for a given queue with an arbitrary payload.
2025
*/
21-
async function createTask(project, location, queue, payload, inSeconds) {
26+
async function createTask(
27+
project = 'my-project-id', // Your GCP Project id
28+
queue = 'my-appengine-queue', // Name of your Queue
29+
location = 'us-central1', // The GCP region of your queue
30+
payload = 'Hello, World!', // The task HTTP request body
31+
inSeconds = 0 // Delay in task execution
32+
) {
2233
// [START cloud_tasks_appengine_create_task]
2334
// [START tasks_quickstart]
2435
// Imports the Google Cloud Tasks library.
@@ -31,8 +42,7 @@ async function createTask(project, location, queue, payload, inSeconds) {
3142
// const project = 'my-project-id';
3243
// const queue = 'my-appengine-queue';
3344
// const location = 'us-central1';
34-
// const payload = 'hello';
35-
// const inSeconds = 30;
45+
// const payload = 'Hello, World!';
3646

3747
// Construct the fully qualified queue name.
3848
const parent = client.queuePath(project, location, queue);
@@ -49,6 +59,7 @@ async function createTask(project, location, queue, payload, inSeconds) {
4959
}
5060

5161
if (inSeconds) {
62+
// The time when the task is scheduled to be attempted.
5263
task.scheduleTime = {
5364
seconds: inSeconds + Date.now() / 1000,
5465
};

cloud-tasks/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
},
1010
"scripts": {
1111
"test": "mocha",
12-
"start": "node server.js"
12+
"start": "node server.js",
13+
"lint": "eslint '**/*.js'"
1314
},
1415
"dependencies": {
1516
"@google-cloud/tasks": "^1.1.0",

cloud-tasks/test/test.samples.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('Cloud Task Sample Tests', () => {
3131
before(async () => {
3232
const client = new CloudTasksClient();
3333
projectId = await client.getProjectId();
34-
url = `https://${projectId}.appspot.com/log_payload`;
34+
url = `https://example.com/taskhandler`;
3535
});
3636

3737
it('should create a queue', () => {
@@ -41,7 +41,7 @@ describe('Cloud Task Sample Tests', () => {
4141

4242
it('should create a task', () => {
4343
const stdout = exec(
44-
`node createTask ${projectId} us-central1 ${queueName}`
44+
`node createTask ${projectId} ${queueName} us-central1`
4545
);
4646
assert.match(stdout, /Created task/);
4747
});
@@ -55,14 +55,14 @@ describe('Cloud Task Sample Tests', () => {
5555

5656
it('should create a HTTP task', () => {
5757
const stdout = exec(
58-
`node createHttpTask ${projectId} us-central1 my-appengine-queue ${url}`
58+
`node createHttpTask ${projectId} my-queue us-central1 ${url}`
5959
);
6060
assert.match(stdout, /Created task/);
6161
});
6262

6363
it('should create a HTTP task with token', () => {
6464
const stdout = exec(
65-
`node createHttpTaskWithToken ${projectId} us-central1 my-appengine-queue ${url} ${SERVICE_ACCOUNT}`
65+
`node createHttpTaskWithToken ${projectId} my-queue us-central1 ${url} ${SERVICE_ACCOUNT}`
6666
);
6767
assert.match(stdout, /Created task/);
6868
});

0 commit comments

Comments
 (0)