Skip to content

A simple queue which lowers the chances of scheduling messages with the same key twice

License

Notifications You must be signed in to change notification settings

clickup/unique-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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();

About

A simple queue which lowers the chances of scheduling messages with the same key twice

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published