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.3.1
  • latest
  • 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
);

Handling connection errors

It's possible to add a onConnectionError callback when creating the beanstalkd-worker. This callback is called when the connection to the queue fails.

const worker = new BeanstalkdWorker(host, port, {
  onConnectionError: (err, tube) => {
    // When there is a connection error, you can stop the watchers
    tube.stop();

    // Eventually, you can restart the watchers
    tube.start();

    // You can access also the complete worker:
    tube.worker.stop();

    // Call process.exit if you want to exit your service completly
    process.exit(1);
  },
});

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 10 May 2021

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