GithubHelp home page GithubHelp logo

rkit / node-beanstalkd-worker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from burstable/node-beanstalkd-worker

0.0 3.0 0.0 21 KB

High level library for running beanstalkd workers in Node.js

License: MIT License

Dockerfile 0.21% JavaScript 99.79%

node-beanstalkd-worker's Introduction

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.

node-beanstalkd-worker's People

Contributors

mickhansen avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.