Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function acknowledgeTask(task) {
// Imports the Google Cloud Tasks library.
const cloudTasks = require('@google-cloud/tasks');
// Instantiates a client.
const client = new cloudTasks.CloudTasksClient();
// Construct the request body.
const request = {
name: task.name,
scheduleTime: task.scheduleTime,
leaseDuration: {
seconds: 600,
},
};
// Send acknowledge task request.
client
.acknowledgeTask(request)
.then(() => {
console.log(`Acknowledged task ${task.name}`);
})
async function createTask(
project = 'my-project-id', // Your GCP Project id
queue = 'my-appengine-queue', // Name of your Queue
location = 'us-central1', // The GCP region of your queue
payload = 'Hello, World!', // The task HTTP request body
inSeconds = 0 // Delay in task execution
) {
// [START cloud_tasks_appengine_create_task]
// [START tasks_quickstart]
// Imports the Google Cloud Tasks library.
const {CloudTasksClient} = require('@google-cloud/tasks');
// Instantiates a client.
const client = new CloudTasksClient();
// TODO(developer): Uncomment these lines and replace with your values.
// const project = 'my-project-id';
// const queue = 'my-appengine-queue';
// const location = 'us-central1';
// const payload = 'Hello, World!';
// Construct the fully qualified queue name.
const parent = client.queuePath(project, location, queue);
const task = {
appEngineHttpRequest: {
httpMethod: 'POST',
relativeUri: '/log_payload',
},
};
async function createHttpTaskWithToken(
project = 'my-project-id', // Your GCP Project id
queue = 'my-queue', // Name of your Queue
location = 'us-central1', // The GCP region of your queue
url = 'https://example.com/taskhandler', // The full url path that the request will be sent to
serviceAccountEmail = 'client@.iam.gserviceaccount.com', // Cloud IAM service account
payload = 'Hello, World!', // The task HTTP request body
inSeconds = 0 // Delay in task execution
) {
// [START cloud_tasks_create_http_task_with_token]
// Imports the Google Cloud Tasks library.
const {CloudTasksClient} = require('@google-cloud/tasks');
// Instantiates a client.
const client = new CloudTasksClient();
// TODO(developer): Uncomment these lines and replace with your values.
// const project = 'my-project-id';
// const queue = 'my-queue';
// const location = 'us-central1';
// const url = 'https://example.com/taskhandler';
// const serviceAccountEmail = 'client@.iam.gserviceaccount.com';
// const payload = 'Hello, World!';
// Construct the fully qualified queue name.
const parent = client.queuePath(project, location, queue);
const task = {
httpRequest: {
httpMethod: 'POST',
url,
function pullTask(project, location, queue) {
// [START cloud_tasks_lease_and_acknowledge_task]
// Imports the Google Cloud Tasks library.
const cloudTasks = require('@google-cloud/tasks');
// Instantiates a client.
const client = new cloudTasks.CloudTasksClient();
// Construct the fully qualified queue name.
const parent = client.queuePath(project, location, queue);
// Construct the request body.
const request = {
parent: parent,
leaseDuration: {
seconds: 600,
},
maxTasks: 1,
responseView: 'FULL',
};
// Send lease task request.
client
async function createHttpTask(
project = 'my-project-id', // Your GCP Project id
queue = 'my-appengine-queue', // Name of your Queue
location = 'us-central1', // The GCP region of your queue
url = 'https://example.com/taskhandler', // The full url path that the request will be sent to
payload = 'Hello, World!', // The task HTTP request body
inSeconds = 0 // Delay in task execution
) {
// [START cloud_tasks_create_http_task]
// Imports the Google Cloud Tasks library.
const {CloudTasksClient} = require('@google-cloud/tasks');
// Instantiates a client.
const client = new CloudTasksClient();
// TODO(developer): Uncomment these lines and replace with your values.
// const project = 'my-project-id';
// const queue = 'my-queue';
// const location = 'us-central1';
// const url = 'https://example.com/taskhandler';
// const payload = 'Hello, World!';
// Construct the fully qualified queue name.
const parent = client.queuePath(project, location, queue);
const task = {
httpRequest: {
httpMethod: 'POST',
url,
},
function main() {
const cloudTasksClient = new CloudTasksClient();
}