18
18
// sample-metadata:
19
19
// title: Cloud Tasks Create HTTP Target with Token
20
20
// description: Create Cloud Tasks with a HTTP Target with Token
21
+ // usage: node createHttpTaskWithToken.js <projectId> <queueName> <location> <url> <serviceAccountEmail> <payload> <delayInSeconds>
21
22
22
23
/**
23
24
* Create a task with an HTTP target for a given queue with an arbitrary payload.
24
25
*/
25
26
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
33
34
) {
34
35
// [START cloud_tasks_create_http_task_with_token]
35
36
// Imports the Google Cloud Tasks library.
@@ -42,17 +43,17 @@ async function createHttpTaskWithToken(
42
43
// const project = 'my-project-id';
43
44
// const queue = 'my-queue';
44
45
// 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! ';
48
49
49
50
// Construct the fully qualified queue name.
50
51
const parent = client . queuePath ( project , location , queue ) ;
51
52
52
53
const task = {
53
54
httpRequest : {
54
55
httpMethod : 'POST' ,
55
- url, //The full url path that the request will be sent to.
56
+ url,
56
57
oidcToken : {
57
58
serviceAccountEmail : email ,
58
59
} ,
@@ -64,6 +65,7 @@ async function createHttpTaskWithToken(
64
65
}
65
66
66
67
if ( inSeconds ) {
68
+ // The time when the task is scheduled to be attempted.
67
69
task . scheduleTime = {
68
70
seconds : inSeconds + Date . now ( ) / 1000 ,
69
71
} ;
0 commit comments