问题描述
我正在使用 node-cron。我想要的是当我的程序启动时 node-cron 应该运行该函数,然后等待 60 mints 并运行该函数,但实际上当我开始执行时 node-cron 并没有在启动时运行该函数,而是在 59 mints 之后运行该函数。 任何帮助将不胜感激。 提前致谢
这是我的代码。
export const surrogate = async () => {
cron.schedule("*/59 * * * *",scheduleFunction);
};
const scheduleFunction = async () => {
console.log("Calling after 59 minutes");
};
解决方法
因为您必须在启动时只调用一次 surrogate
:
export const surrogate = async () => {
scheduleFunction();
cron.schedule("*/59 * * * *",scheduleFunction);
};