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

reliable_queue

v2.4.0

Published

Reliable Queue on top of Redis. See http://redis.io/commands/rpoplpush#pattern-reliable-queue

Downloads

4

Readme

Reliable Queue on top of Redis

Build Status PRs Welcome dependencies Status codecov

Redis is often used as a messaging server to implement processing of background jobs or other kinds of messaging tasks. A simple form of queue is often obtained pushing values into a list in the producer side, and waiting for this values in the consumer side using RPOP (using polling), or BRPOP if the client is better served by a blocking operation.

However in this context the obtained queue is not reliable as messages can be lost, for example in the case there is a network problem or if the consumer crashes just after the message is received but it is still to process. RPOPLPUSH (or BRPOPLPUSH for the blocking variant) offers a way to avoid this problem: the consumer fetches the message and at the same time pushes it into a processing list.

It will use the LREM command in order to remove the message from the processing list once the message has been processed. An additional client may monitor the processing list for items that remain there for too much time, and will push those timed out items into the queue again if needed.

See: http://redis.io/commands/rpoplpush#pattern-reliable-queue

Correct working on redis cluster

Requirements

  • Redis >= 2.4 (because of redis rpush feature)
  • Node.js >= 8.11.3

Usage

const { ReliableQueue } = require('reliable_queue')
const redis = require('redis')

const queue = new ReliableQueue({
  prefix: '{my_awesome_queue}', // Optional prefix. See: https://redis.io/topics/cluster-spec#keys-hash-tags
  redisClient: redis.createClient(), // Redis client. See https://github.com/NodeRedis/node_redis or similar interface
  timeoutSec: 120, // Optional. Zero by default. It can be used to block connection indefinitely.
})

// For instance, we have idempotent tasks
// that means we can retry the task with the same effect
(async () => {

  // This is how we add our task/tasks to a queue
  const queueLength = await queue.push([{
    name: 'My great json task'
  }])

  console.info(`Queue length is ${queueLength}`)

  const task = await queue.pop()

  console.log(`${task.data} is ok`)

  // our task was finished success or task.reject('The reason why') ?
  task.success()

})()
  .catch(console.error)

See examples

Events

You can subscribe on queue events

queue.on('success', job => {
  // your code here
})
  • push - Adding to queue
  • pop - Popping from queue
  • reject - Job rejection event
  • success - Success prepared job