const Bull = require('bull'); const { BullAdapter } = require('bull-board/bullAdapter');
前提要在 package.json 中添加以上库,例如:
"dependencies": { "bull": "^3.5.0", "bull-board": "^1.9.12", "cron": "^1.8.2" },
const queue = new Bull('queueName', {redis: {port: REDIS_PORT, host: REDIS_HOST}});
queue.process(async (job) => { // do something with job data });
// 例如:每1分钟触发一次 new CronJob('*/1 * * * *', async () => { await queue.add({data: 'jobData'}); }, null, true, 'Asia/Shanghai');
在这里,job 对象将会被创建并添加到队列中,触发队列处理程序。