Rohit Kumar
Rohit Kumar

Reputation: 849

How to delete Google task from Google Task queue programmatically using Node.js?

How to delete a task from Google Task queue programmatically using Node.js?

Documentation doesn't tell us anything about it in Node.js

Task Queue Link

Upvotes: 2

Views: 553

Answers (1)

Andie Vanille
Andie Vanille

Reputation: 820

I found this documentation and this one that mention how to delete the task. Only please keep in mind that a task cannot be deleted if it has executed successfully or permanently failed.

This is the code that the Google's documentation mentions :

const {google} = require('googleapis');
const cloudtasks = google.cloudtasks('v2beta3');

async function main () {
  const authClient = await authorize();
  const request = {
    // Required. The task name. For example:
    // `projects/PROJECT_ID/locations/LOCATION_ID/queues/QUEUE_ID/tasks/TASK_ID`
    name: 'projects/my-project/locations/my-location/queues/my-queue/tasks/my-task',  // TODO: Update placeholder value.

    auth: authClient,
  };

  try {
    await cloudtasks.projects.locations.queues.tasks.delete(request);
  } catch (err) {
    console.error(err);
  }
}
main();

async function authorize() {
  const auth = new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform']
  });
  return await auth.getClient();
}

I really hope that this information helps you :)

Upvotes: 1

Related Questions