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

ts-mongo-queue

v1.4.0

Published

mongo-queue typescript implementation

Downloads

1,322

Readme

ts-mongo-queue

A TypeScript library for managing queues using MongoDB.

Technology

MongoDB TYPESCRIPT JAVASCRIPT NODE

WHO SHOULD USE

Any developer who needs mongodb-queue with support to mongodb-7 and node driver 6.0.1.

AUTHOR

Marcus Yoda @marcusyoda

Installation

npm install ts-mongo-queue

Or with Yarn:

yarn add ts-mongo-queue

Basic Usage

First, import the necessary functions and classes:

import { MongoClient } from 'mongodb'
import { MongoQueue } from 'ts-mongo-queue'

Next, create an instance of MongoQueue:

const client = new MongoClient('your_mongodb_connection_string')
const queue = MongoQueue(client, 'your_queue_name')

Add a Message to the Queue

const payload = { data: 'test' }
const result = await queue.add(payload)
console.log(result.messageId)

Fetch the Next Message from the Queue

const nextMessage = await queue.get()
console.log(nextMessage.payload)

Certainly! I'll enhance the "Configuration" section based on the initial information you provided about the library.


Configuration

ts-mongo-queue provides a range of configurations to tailor the queue to your specific needs. When creating a new instance of MongoQueue, you can provide an optional opts object to configure the behavior:

const queue = MongoQueue(client, 'your_queue_name', {
  visibility: 30,
  delay: 10,
  deadQueue: new Queue(client, 'dead_queue_name'),
  maxRetries: 5,
})

Options

  • visibility: The duration (in seconds) a message remains hidden from get after being fetched, providing the consumer a window to process and delete the message. Defaults to 30 seconds.

  • delay: The duration (in seconds) a message waits before becoming visible for the first time. Useful for scheduled jobs or delayed processing. Defaults to no delay.

  • deadQueue: An optional instance of another Queue where messages that exceed the maxRetries count are moved. If not provided, messages that fail repeatedly will remain in the primary queue.

  • maxRetries: The maximum number of attempts to fetch a message before it's considered dead and, if a deadQueue is provided, moved there. Defaults to infinite retries.

Environment Configurations

Some configurations can also be set using environment variables:

  • QUEUE_GET_RECURSION_LIMIT: Set a limit on how many times the library should attempt to fetch a message recursively. This can be crucial to prevent potential infinite loops or excessive recursions. Default value is 500.

For setting the environment variable:

export QUEUE_GET_RECURSION_LIMIT=1000

Testing

The library is fully tested. To run tests:

yarn test

Contributing

Feel free to open issues or pull requests if you'd like to improve or fix something in the library!

License

MIT