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

beanstalkd-worker

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

beanstalkd-worker

High level library for running beanstalkd workers in Node.js

  • 1.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

Beanstalkd Worker for node

Features

  • Wait for job completion
  • Child jobs (keeping parent alive till done)

How-To

Setup

npm install --save beanstalkd-worker
import BeanstalkdWorker from 'beanstalkd-worker';

const worker = new BeanstalkdWorker(
  host, // beanstalkd host
  port, // beanstalkd port
);

Spawning jobs

worker.spawn(tube, {
  // job payload/values
}, {
  delay: 0,
  priority: 1000,
  timeout: 10 * 60 * 1000 // ms
}).then(function (job) {
  console.log(job.id);
});

Handling jobs

worker.handle(tube, function (payload) {
  // Complete job
  return Promise.resolve();

  // Job error
  return Promise.reject();

  // Spawn a job
  this.spawn(someTub);

  // Refresh timeout
  this.touch();

  // Spawn child job and wait for completion before completing this job
  await this.child(anotherTube, {/* payload */});

  // Await another job
  await this.wait(anotherTube, jobId);

  // Puts current job back in queue with delay, does not affect retries counter
  return this.delay(5000); // ms, default: original timeout
}, {
  tries: 3, // Total amount of tries including the first one
  backoff: {
    initial: 60 * 1000, // ms
    exponential: 1.5 // multiple backoff by N each try
  }
});

worker.start(); // Enable handlers and start processing jobs, make sure handlers are setup before calling start

Keep in mind that worker will spawn a connection equal to width * amount of tubes. You'll want to make sure that your server is configured to handle that amount of connections (ulimit).

Debugging

Use DEBUG=beanstalkd-worker* to enable verbose debugging.

Keywords

FAQs

Package last updated on 26 Aug 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