Giter VIP home page Giter VIP logo

unique-queue's Introduction

@time-loop/unique-queue: A simple queue which lowers the chances of scheduling messages with the same key twice

A simple queue which lowers the chances of scheduling messages with the same key twice. It still does NOT guarantee that the message processing function will be a singleton though: it may happen that it's started at 2 places for the same key if this key is scheduled twice after it's been picked up. To guarantee a single running instance, another library must be used from inside the subscription callback.

There is also no support for retries of failed jobs recovery. This is because in practice a recovery needs to be done at a higher level often times, otherwise "dead letter queue" would accumulate forever.

Example

// You can also use Redis Cluster here.
export const redis = new Redis({
  host: process.env.REDIS_WORKER_HOST,
  port: process.env.REDIS_WORKER_PORT,
  password: process.env.REDIS_WORKER_PASS,
  keyPrefix: "queue:",
});

const queue = new Queue<
  | {
      type: "type1";
      key: string;
      some: string;
    }
  | {
      type: "type2";
      key: string;
      other: string;
    }
>({
  redis,
  namespace: "my-queue",
});

// ...

await queue.push({ type: "type1", key: "some", some: "some" }, 10);

// ...

queue.subscribe("type1", (message) => console.log(message));

// ...

const promise = queue.run();
// ...
promise.abort();

unique-queue's People

Contributors

swyrwiak-cu avatar dimikot avatar

Watchers

 avatar Alex Yurkowski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.