https://github.com/clickup/unique-queue
A simple queue which lowers the chances of scheduling messages with the same key twice
https://github.com/clickup/unique-queue
Last synced: 12 months ago
JSON representation
A simple queue which lowers the chances of scheduling messages with the same key twice
- Host: GitHub
- URL: https://github.com/clickup/unique-queue
- Owner: clickup
- License: mit
- Created: 2024-01-10T10:12:20.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-02-20T16:23:49.000Z (over 1 year ago)
- Last Synced: 2025-03-05T16:55:25.572Z (over 1 year ago)
- Language: TypeScript
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @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
```ts
// 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();
```