@ysd-runner/safe-timeout
v1.0.0
Published
基于setTimeout+Redis实现的定时任务,服务重启时会自动监测
Downloads
2
Readme
node-timingtask
基于setTimeout+Redis实现的定时任务,服务重启时会自动监测
const redis = require('redis');
const redisClient = redis.createClient(6379, '127.0.0.1', { db: 2 });
const timingTask = require('node-timingtask')(redisClient);//初始化该模块,当服务重启时,会采取默认的随机时间,检测任务
timingTask.registeTimingTaskFunc(log);
function log(msg) {
console.log(`now:${new Date()} msg:${msg}`);
}
timingTask.addTimingTask(log.name, ['hello1'], 1000);
const redis = require('redis');
const redisClient = redis.createClient(6379, '127.0.0.1', { db: 2 });
/**
*使用这种方式,当服务重启时,会在callback调用时,检测任务。
*/
const timingTask = require('node-timingtask')(redisClient, (callback) => {
setTimeout(() => {
callback();
}, 5000);
});
timingTask.registeTimingTaskFunc(log);
function log(msg) {
// console.log(`now:${new Date()} msg:${msg}`);
}