Socket
Socket
Sign inDemoInstall

@google-cloud/tasks

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/tasks

Cloud Tasks API client for Node.js


Version published
Weekly downloads
281K
decreased by-5.31%
Maintainers
1
Weekly downloads
 
Created

What is @google-cloud/tasks?

@google-cloud/tasks is a Node.js client library for Google Cloud Tasks, which allows you to manage the execution of large numbers of distributed requests. It provides a way to create, manage, and dispatch tasks to App Engine, HTTP, or Cloud Pub/Sub targets.

What are @google-cloud/tasks's main functionalities?

Create a Task

This feature allows you to create a new task in a specified queue. The task can be an HTTP request with a payload.

const {CloudTasksClient} = require('@google-cloud/tasks');
const client = new CloudTasksClient();

async function createTask() {
  const project = 'my-project-id';
  const queue = 'my-queue';
  const location = 'us-central1';
  const url = 'https://example.com/taskhandler';
  const payload = 'Hello, World!';

  const parent = client.queuePath(project, location, queue);
  const task = {
    httpRequest: {
      httpMethod: 'POST',
      url,
      body: Buffer.from(payload).toString('base64'),
      headers: {
        'Content-Type': 'application/json',
      },
    },
  };

  const request = {parent, task};
  const [response] = await client.createTask(request);
  console.log(`Created task ${response.name}`);
}

createTask().catch(console.error);

Delete a Task

This feature allows you to delete a specified task from a queue.

const {CloudTasksClient} = require('@google-cloud/tasks');
const client = new CloudTasksClient();

async function deleteTask() {
  const project = 'my-project-id';
  const queue = 'my-queue';
  const location = 'us-central1';
  const task = 'my-task-id';

  const name = client.taskPath(project, location, queue, task);
  await client.deleteTask({name});
  console.log(`Deleted task ${name}`);
}

deleteTask().catch(console.error);

List Tasks

This feature allows you to list all tasks in a specified queue.

const {CloudTasksClient} = require('@google-cloud/tasks');
const client = new CloudTasksClient();

async function listTasks() {
  const project = 'my-project-id';
  const queue = 'my-queue';
  const location = 'us-central1';

  const parent = client.queuePath(project, location, queue);
  const [tasks] = await client.listTasks({parent});
  tasks.forEach(task => {
    console.log(`Task: ${task.name}`);
  });
}

listTasks().catch(console.error);

Other packages similar to @google-cloud/tasks

Keywords

FAQs

Package last updated on 22 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc