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

theta-mn-queue

v3.0.6

Published

An easy to use queue system with support for multiple data sources

Downloads

14

Readme

Theta MN Queue

Theta Queue is an easy to use queue system with support for multiple data sources developed in TypeScript and has been designed and developed from the ground up.

Important: This library is currently in active development and the public API might get changed, until the design and APIs have been locked. Use this library wisely.

Badges

MIT License npm Open Source Helpers Contributor Covenant TypeScript NodeJS

Changelog

A history of changes have been given in the file CHANGELOG.md (https://github.com/mustafaneguib/theta-mn-queue/blob/master/CHANGELOG.md)

Installation

Install theta-mn-queue with npm

  npm i theta-mn-queue

or

  yarn add theta-mn-queue

Usage/Examples

import { Queue, Document } from 'theta-mn-queue';

/**
 * The method setupQueue itself is given for demonstration purposes.
 */
async function setupQueue() {

  let queue_name = 'queue1';
  //A new queue will be created with the name queue1
  let queue: Queue = new Queue(queue_name);
  await queue.purge();//This method will remove any lingering queues in the database that have the same name as the one that has been provided.

  //A new document has been created and is being queued into the queue. The method call queue.getNextIndex() returns the next usable index. Use this method to get a sequence of numbers that can be used as ids.
  let document: Document = new Document({id: (await queue.getNextIndex()), key: 'hello', content: 'world'});
  await queue.enqueue(document);
  
  document = new Document({id: (await queue.getNextIndex()), key: 'hello', content: 'world'});
  await queue.enqueue(document);

  //At this stage the queue will be containing two items

  //The commit method ensures that the queue is persisted and saved to the database.
  await queue.commit();

}

setupQueue();

API

Resource

This is a TypeScript interface that is being used as a type and has the following structure:

{
    id: number;
    key: string;
    content: string;    
}

This is the basic type that gets stored in the data storage as well. The definition of this type has only been given for sake of completion and is not exported and should not be used directly. The Document class uses Resource type directly.

Document

public getResource(): Resource

The getResource method returns a Resource type.

public getId(): number

The getItd method gets the id of the document.

public getKey(): string

The getKey method gets the key of the document.

public getContent(): string

The getContent method gets the content of the document.

The public methods of QueueProcessor accept the Document object where required.

Queue

public getName(): string

This method returns the name of the queue

public async initialize(): Promise

This method initializes the queue and sets up the required infrastructure for the queue to function smoothly

public async commit(): Promise

This method writes to the designated data storage persisting it permanently unless removed from the data storage.

public async purge(): Promise

This method purges(removes) the queue from the database.

public async enqueue(document: Document): Promise

This method enqueues the document to the back of the queue.

public async dequeue(): Promise

This method dequeues the document from the front of the queue and returns it.

public async peek(): Promise

This method returns the document at the front of the queue without removing it from the queue.

public async isEmpty(): Promise

This method returns whether the queue is empty or not.

public async length(): Promise

This method returns the number of items in the queue.

public async getNextIndex(): Promise

This method gets the next index of the queue

Features

The features that have been marked as check have been implemented while those that are planned to be implemented are marked as unchecked.

  • [x] Queue implementation with public API
  • [x] Structured architecture for clean and easy development
  • [x] Single file based persistant layer
  • [X] Redis based persistant layer
  • [X] Code of conduct document
  • [X] Changelog document
  • [X] Unit Tests
  • [X] Add support for multiple/parallel queues
  • [ ] Add support for job scheduling (Inprogress)
  • [ ] Rate limiting of jobs
  • [ ] Contribution documentation and plan of action
  • [ ] MySQL based persistant layer
  • [ ] MongoDB based persistant layer
  • [ ] PostgreSQL based persistant layer

Environment Variables

Please refer to the file .env.example that has been provided in the codebase with keys and their sample values.

BASE_URL PORT MONGO_URL REDIS_PORT DATA_DRIVER

Tech Stack

Server: TypeScript, NodeJS

Authors

Feedback

If you have any feedback, please reach out to us at [email protected]

Contributing

Theta MN Queue is in active development and invites software engineers and software developers to help us in making this library one of the best queue and job scheduling library that there can be. We are actively seeking contributors to help us take this project forward.

We are also interested in getting help in improving the documentation for this project so that it is easy to read and understand.

If you find a bug in the code do create an issue in the issue tracker https://github.com/mustafaneguib/theta-mn-queue/issues and if you work on fixing it do create a merge request with the details of the fix so that it can be applied.

License

MIT