优化架构,新增路由

This commit is contained in:
robin
2022-06-04 11:43:05 +08:00
parent ba9ca43729
commit 264ab8d979
22 changed files with 161 additions and 60 deletions
+10 -4
View File
@@ -3,7 +3,7 @@
* 加载schedule文件夹下的任务
* https://blog.pincman.com/archives/18/
* https://docs.bullmq.io
*
* https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md
*/
const config = require("./config")
// const schedule = require("./schedule")
@@ -15,17 +15,23 @@ module.exports = async (app) => {
const queueName = "boobam_schedule"
const queue = mq.Queue(queueName);
mq.QueueScheduler(queueName);//处理延时任务
await queue.obliterate();//清空所有定时任务
try {
await queue.drain();//清空所有定时任务
await queue.obliterate();//清空所有定时任务
} catch (err) {
console.log("清空任务失败,新改动的任务可能没有生效:", err)
}
const list = await app.load(config.path)
//等待所有插件载入完成后,启动Worker
app.willReadyList.push(async () => {
for (let el of list) {
mq.Worker(queueName, async job => {
if (job.name===el.parse.name){
if (job.name === el.parse.name) {
el.res.fun(app)
}
});
await queue.add(el.parse.name,{},{
await queue.add(el.parse.name, {}, {
repeat: el.res.time,
})
}