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

eazy-queue-mongo-ks

v0.2.1

Published

EzqMongo is a simple event-driven queue processing library for Node.js that is built on top of Mongoose and EventEmitter. It provides a way to manage and process queues in a MongoDB database with ease. This README provides an overview of the library and h

Downloads

3

Readme

EzqMongo

EzqMongo is a simple event-driven queue processing library for Node.js that is built on top of Mongoose and EventEmitter. It provides a way to manage and process queues in a MongoDB database with ease. This README provides an overview of the library and how to use it in your Node.js applications.

Installation

npm install eazy-queue-mongo-ks

Import

commonJS:

const EzqMongo = require('eazy-queue-mongo-ks');

es2015:

import EzqMongo from 'eazy-queue-mongo-ks';

please set your mongodb connection in env MONGO_URL

API

new EzqMongo(queueName?: string, stackLimit?: number)

  • queueName (optional): The name of the queue. Default is 'ezq'.
  • stackLimit (optional): The maximum number of items to process at once. Default is 1.

add(data: T | T[])

Add data to the queue. You can pass a single item or an array of items. in array is limit 100

process(callback: (data: T | undefined) => Promise<void>)

The process method is used to process items in the queue by invoking the provided callback function. It processes items one by one until the queue is empty or until an error occurs.

checkQueue()

The checkQueue method is used to check the number of items in the queue. It returns a promise that resolves to the count of items in the queue.

clearQueue()

Clear the entire queue. Use this with caution, as it removes all data in the queue.

Events

EzqMongo emits the following events that you can listen for:

  • job: Triggered when a job is available for processing.
  • done: Triggered after processing a job. Provides the processing result and the processed data.
  • complete: Triggered when the entire queue processing is complete.

Usage

Here's a basic example of how to use EzqMongo in your Node.js application:

import EzqMongo from 'eazy-queue-mongo-ks';
import mongoose from 'mongoose';

mongoose.connect('your-mongodb/your-db');

// Create an instance of EzqMongo with a custom queue name and an optional stack limit
const ezqMongo = new EzqMongo('myQueue', 10);

// Listen for events
ezqMongo.on('job', () => {
  // Process the queue with the defined callback
  ezqMongo.process(async (job) => {
    await somethingAsync(job);
    // ...TODO
    return `ok ${job}`; // Not require return
  });
});

// Add data to the queue
ezqMongo.add({ name: 'foo' });
// Or
ezqMongo.add([{ name: 'foo' }, { name: 'bar' }]);

ezqMongo.on('done', (result, data) => {
  // If ezq.process is return ezqMongo.process. example return `ok {name: 'foo'}`
  // Job is data of process. example {name: 'foo'}
  console.log('Done :', result, data);
});

ezqMongo.on('complete', () => {
  // All job is done
  console.log('Queue processing complete');
});

// Clear the queue (use with caution, as it removes all data in the queue) Mongo deleteMany with queueName
ezqMongo.clearQueue();

Issues and Contributions

If you encounter any issues or have suggestions for improvements, please open an issue on the GitHub repository.