@nerimity/mimiqueue
Advanced tools
Comparing version 1.2.3 to 2.0.0
{ | ||
"name": "@nerimity/mimiqueue", | ||
"version": "1.2.3", | ||
"version": "2.0.0", | ||
"description": "NodeJS group queuing library. Requires Redis.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.mjs", |
121
readme.md
# Mimiqueue | ||
### Features | ||
- Cluster Support | ||
- Redis Required | ||
- Group Queuing | ||
- Throttle Support (minTime) | ||
### Installation | ||
@@ -12,4 +19,4 @@ | ||
```ts | ||
import { createQueue, createQueueProcessor } from "@nerimity/mimiqueue"; | ||
import { createClient } from "redis"; | ||
import { Queue } from "@nerimity/mimiqueue"; | ||
import { setTimeout } from "timers/promises"; | ||
@@ -24,91 +31,37 @@ | ||
await redisClient.connect(); | ||
await redisClient.flushAll(); | ||
const main = async () => { | ||
await redisClient.connect(); | ||
const addFriendQueue = new Queue({ | ||
redisClient, | ||
name: "addFriend", | ||
process: async (data) => { | ||
await setTimeout(2000); | ||
return { done: "lol", data }; | ||
}, | ||
}); | ||
// NOTE: | ||
// When running in a cluster, this needs to be ran ONCE in the main thread. | ||
await createQueueProcessor({ | ||
redisClient, | ||
}); | ||
addFriendQueue.add({ someData: 1 }, { groupName: "1234" }).then((res) => { | ||
console.log(res); | ||
}); | ||
addFriendQueue.add("hello", { groupName: "1234" }).then((res) => { | ||
console.log(res); | ||
}); | ||
addFriendQueue.add(123).then((res) => { | ||
console.log(res); | ||
}); | ||
``` | ||
const queue = await createQueue({ | ||
name: "test-queue", | ||
redisClient, | ||
minTime: 1000, | ||
}); | ||
## Alt Usage | ||
queue.add( | ||
async () => { | ||
await setTimeout(5000); | ||
return "done"; | ||
}, | ||
{ groupName: "someId eg ip address" } | ||
); | ||
```ts | ||
import { createClient } from "redis"; | ||
import { AltQueue } from "@nerimity/mimiqueue"; | ||
import { setTimeout } from "timers/promises"; | ||
const status = await queue.add( | ||
async () => { | ||
await setTimeout(5000); | ||
return "done"; | ||
}, | ||
{ groupName: "someId eg ip address" } | ||
); | ||
const redisClient = createClient({ | ||
socket: { | ||
host: "127.0.0.1", | ||
port: 6379, | ||
}, | ||
}); | ||
console.log(status); | ||
}; | ||
await redisClient.connect(); | ||
await redisClient.flushAll(); | ||
const queue = new AltQueue({ | ||
redisClient, | ||
name: "addFriend", | ||
}); | ||
async function doSomething(groupName) { | ||
const done = await queue.start({ groupName }); | ||
console.log("doing something"); | ||
await setTimeout(1000); | ||
done(); | ||
} | ||
doSomething("123"); | ||
doSomething("123"); | ||
main(); | ||
``` | ||
## Alt 2 Usage | ||
```ts | ||
import { createClient } from "redis"; | ||
import { AltQueue2 } from "@nerimity/mimiqueue"; | ||
import { setTimeout } from "timers/promises"; | ||
const redisClient = createClient({ | ||
socket: { | ||
host: "127.0.0.1", | ||
port: 6379, | ||
}, | ||
}); | ||
await redisClient.connect(); | ||
await redisClient.flushAll(); | ||
const queue = new AltQueue2({ | ||
redisClient, | ||
name: "addFriend", | ||
}); | ||
async function queueDoSomething(groupName) { | ||
queue.add(() => doSomething(groupName), { groupName }); | ||
} | ||
async function doSomething(groupName) { | ||
console.log("doing something"); | ||
await setTimeout(1000); | ||
} | ||
queueDoSomething("123"); | ||
queueDoSomething("123"); | ||
``` |
@@ -1,4 +0,2 @@ | ||
export * from "./Queue"; | ||
export * from "./AltQueue"; | ||
export * from "./AltQueue2"; | ||
export * from "./Timeout"; | ||
export { createQueue } from "./createQueue"; | ||
export { createQueueProcessor } from "./createQueueProcessor"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
20308
15
279
66
1