Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@google-cloud/tasks

Package Overview
Dependencies
Maintainers
1
Versions
65
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

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
227K
decreased by-19.28%
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 07 Jul 2020

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