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

persistent-bag

v0.0.1

Published

This is to bags like redis is to queues. A bag (or multiset) is filled over time and processed at once.

Downloads

2

Readme

This is to bags like redis is to queues. A bag (or multiset) is filled over time and processed at once.

Table of Contents: Overview, Install, Use, Dependencies, Todos/ Contribution

Overview

This node module persistent-bag aims to be a persistent bag (also called multiset) for accumulating data over the lifetime of an application and then emitting the data after a fixed interval in one aggregated object. Goal is to work like redis but not process the entries (or jobs) individually, but aggregated by time intervals. Therefore the API is a bit designed like kue (but not as good).

Install

Business as usual: npm install persistent-bag --save.

The MySQL database (see below) needs already to be set up. The tables are auto-generated on first launch.

Use

Examples can also be found in /samples.

Init persistent-bag

const PersistentBag = require('../index');
const bag = new PersistentBag({
  host: 'localhost',
  port: '3306',
  user: 'root',
  password: '',
  database: 'test'
});

This initializes the persistent-bag and opens the connection to the MySQL database for persistence. If the required data structure (i.e. one table called _persistent-bag) does not exist yet, it will be created.

Add something to a bag

bag.add({ test: false }, function (err, dataId) {
  console.log('Entry id: ' + dataId);
});

There is only one large bag where items can be add()ed to. So right now, there's no way to have two logical types of bag at the same time (see todos).

Although in fact, each new time interval (fixed to 15 minutes) is it's own bag, which is emitted right after the time interval for this bag is over. By the way, we could also make the time interval dynamic (see todos).

Process a bag

bag.process(function worker(bag, done) {

  console.log(bag.data);

  setTimeout(function () {
    done();
  }, 1000);

});

Processing bags is done by subscribing to persistent-bag as listed above. This supplied worker function then gets the whole bag with the aggregated data that has been added in bag.data.

After the bag has been processed, the provided callback done() needs to be called. This tells persistent-bag to emit the next bag. If done(err) is called with an error, the bag will not be marked as successfully processed and emitted again.

Dependencies

The items in the bag are stored persistently using a MySQL database, so first and most obvious dependecy is MySQL.

Furthermore, several npm modules are added as dependencies in the package.json. Those are:

TODOs and Contribution

If you want to contribute, please do. Some suggestions:

  1. Enable different types of bag: Just like kue has different type of jobs, we want different type of bags.
  2. Make time interval dynamic: Currently, a new bag is created and emitted every 15 minutes. It would be useful to make this dynamic somehow, while stilling enabling persistence.