npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@compwright/worker-bee

v1.1.1

Published

A process wrapper for Bee-Queue workers

Downloads

11

Readme

@compwright/worker-bee

Build Status Code Climate Test Coverage Dependency Status Download Status Sponsor on GitHub

A process wrapper for Bee-Queue workers.

Installation

npm install --save @compwright/worker-bee

Basic Usage

Single-threaded usage:

const Queue = require('bee-queue');
const Worker = require('@compwright/worker-bee');

const queue = new Queue('test-queue');

worker = new Worker(queue);

worker.start(async (job) => {
  job.reportProgress(100);
  console.log(`Job ${job.id} completed`);
});

Pressing CTRL+C or sending a SIGINT or SIGTERM signal will cause the worker to gracefully shut down and exit.

Cluster Usage

Bee-Queue supports workers in multiple processes or servers. Here is a multi-process worker example using the throng process manager:

const throng = require('throng');
const Queue = require('bee-queue');
const Worker = require('@compwright/worker-bee');

function timeout(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

// throng by default forks one worker per CPU
throng(pid => {
  console.log(`Worker ${pid} started`);

  const queue = new Queue('test-queue');

  const logger = {
    log: (...args) => console.log(`[${pid}]`, ...args),
    error: (...args) => console.error(`[${pid}]`, ...args),
  };

  // handle six jobs concurrently per worker process
  worker = new Worker(queue, { concurrency: 6, logger });

  worker.start(async (job) => {
    for (var i = 0; i < 5; i++) {
      job.reportProgress(100 * i / 5);
    }
    console.log(`Job ${job.id} completed`);
  });
});

Throng will relay the shutdown signal to each worker process to tell them to gracefully shut down and exit.

Documentation

new Worker(queue, [options])

Returns a new worker instance initialized with the given options.

Options:

  • queue - A Bee-Queue queue instance
  • shutdownTimeout (optional) - time to wait in milliseconds for worker processing to stop before terminating (see Queue.close())
  • stalledCheckInterval (optional) - how often to check for stalled jobs in milliseconds (see Queue.checkStalledJobs())
  • concurrency (optional) - how many jobs to process concurrently within the worker thread (see Queue.process())
  • logger (optional) - logger instance to use instead of console (must be interface-compatible with console)

worker.start(callbackFn)

Listen for jobs to process.

Options:

  • callbackFn - a function to execute the job. Receives the job as the first argument.

worker.stop(error)

Stop listening for jobs to process.

Called automatically on SIGINT or SIGTERM signals (such as CTRL+C), and if an uncaught exception occurs.

Options:

  • error - an error object to associate with the shutdown. If passed, causes a non-zero exit code.

License

Copyright (c) 2019

Licensed under the MIT license.