MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / quickstart

Function quickstart

cloud-tasks/snippets/quickstart.js:28–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26 const client = new CloudTasksClient();
27
28 async function quickstart() {
29 // TODO(developer): Uncomment these lines and replace with your values.
30 // const project = 'my-project-id';
31 // const queue = 'my-appengine-queue';
32 // const location = 'us-central1';
33 // const payload = 'hello';
34
35 // Construct the fully qualified queue name.
36 const parent = client.queuePath(project, location, queue);
37
38 const task = {
39 appEngineHttpRequest: {
40 httpMethod: 'POST',
41 relativeUri: '/log_payload',
42 },
43 };
44
45 if (payload) {
46 task.appEngineHttpRequest.body = Buffer.from(payload).toString('base64');
47 }
48
49 if (inSeconds) {
50 task.scheduleTime = {
51 seconds: inSeconds + Date.now() / 1000,
52 };
53 }
54
55 const request = {
56 parent: parent,
57 task: task,
58 };
59
60 console.log('Sending task:');
61 console.log(task);
62 // Send create task request.
63 const [response] = await client.createTask(request);
64 const name = response.name;
65 console.log(`Created task ${name}`);
66 }
67 quickstart();
68 // [END cloud_tasks_quickstart]
69}

Callers 1

mainFunction · 0.70

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected