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

nsquishy-worker

v0.3.1

Published

An opinionated NSQ worker framework using **[nsquishy](https://github.com/stongo/nsquishy)**. Based on **[nsqjs](https://github.com/dudleycarr/nsqjs)** to simplify workers using NSQ. This module takes care of lots of trivial setup such as logging and disc

Downloads

7

Readme

Nsquishy Worker

An opinionated NSQ worker framework using nsquishy. Based on nsqjs to simplify workers using NSQ. This module takes care of lots of trivial setup such as logging and discovery, and follows an established pattern we've been using at &yet to rapidly create and deploy NSQ workers anywhere.

Configuration

  • nsquishyOptions [object] - See nsquishy for options. Defaults to using nsqd on 127.0.0.1:4150 on topic "events" and channel "nsquishy-worker"
  • writer [boolean] - Whether to include an NSQ writer or not (reader included by default). Defaults to false
  • pre [function] - A function to modify the msg and msgBody before passing it through the chain. Takes msg, msgBody and callback as arguments. Callback expects the signature callback(err, msg, msgBody)
  • match [function] - Should return true or false after analyzing msg and msgBody of the received NSQ message. Takes msg, msgBody as an argument. When returning true, the following job function is executed
  • job [function] - The meat of your worker. This is where you process the NSQ message and do whatever you want. Takes msg, msgBody and callback as arguments. Callback expects the signature callback(err, data), with data being any information you want to pass to the finish function
  • finish [function] - The action to take after the job has finished running. Takes data, msg, msgBody, next as arguments. Here's where you would publish another message, write logs, etc. next signature is next(err)

Context

All the functions listed on the configuration above have access to the following methods and properties in this

  • nsqReader - a pre-configured nsqjs reader
  • nsqWriter - a pre-configured nsqjs writer (if writer set to true in configuration)
  • nsquishyOptions - settings used in configuration
  • nsquishy - the instantiated nsquishy object
  • Message - nsquishy-message constructor for creating new messages

Opinions

  • Unique Channels - Distinct workers that listen to the same topic should all have unique channels. For instance, if you have two worker types, "alert-worker" and "log-worker", interested in topic "metrics", set all pooled alert-workers to channel "alert-worker" and all log-workers to channel "log-worker."
  • Finish all messages - since all channels get their own stream of a given topic, if a worker isn't interested in a message, it should finish it. This won't disturb other channels and keeps the nsqd queues under control. Nsquishy Worker handles this for you, so you don't need to do anything in the finish function
  • Standardized message bodies - it is highly recommended to publish messages using nsquishy-message to avoid complexity as worker types scale. The message constructor comes bundled already with nsquishy-worker
  • Horizontal Scaling - The core Nsquishy module used in this module allows worker to connect to nsqd or nsqlookupd by manually specifying their addresses, or by reading etcd keys where the host information is stored. This allows for easy clustering on hosts such as CoreOS
  • Plugable - check soon for other modules that can be used for the match, job and finish functions

Example

See example/index.js