函数?"/>
如何在 Nodejs 中使用 bull 包在到期时间运行函数?
我是 Nodejs 的新手,并尝试在 Nodejs 中使用 bull 包来在 expirationTime 上运行一个函数?谁能给我一个基本的代码示例来做这件事?
import Queue from 'bull';
function scheduleDeleteUser(email, expirationTime) {
const deleteUserQueue = new Queue('deleteUserQueue');
deleteUserQueue.process(() => {
deleteArray();
console.log(' array deleted.');
});
deleteUserQueue.resume();
const job = deleteUserQueue.add({ email }, {
delay: expirationTime.getTime() - Date.now(),
});
console.log(`Job scheduled to run at ${expirationTime}.`);
return job;
}
const email = '[email protected]';
const now = new Date();
const futureTime = now.getTime() + 20000;
const expirationTime = new Date(futureTime);
console.log(expirationTime);
scheduleDeleteUser(email, expirationTime);
回答如下:
更多推荐
如何在 Nodejs 中使用 bull 包在到期时间运行函数?
发布评论