我想在特定时间(每5分钟)通过soap api从几台机器获取信息,所以我使用节点调度,我想根据我数据库中的每台机器制定几个调度。我正在使用此代码:
//fetch machines configrations
function readMachinesConfig() {
return pool.query("SELECT * FROM machines").then(res => {
const machines = {};
res.rows.map(machine => {
let machine_line = machine.machine_name + "/" + machine.machine_line;
machines[machine_line] = { url: machine.url, scantime: machine.scantime };
});
return machines;
});
}
readMachinesConfig().then(res => {
Object.keys(res).map((machine, index) => {
let scantime = "*/" + res[machine].scantime + " * * * *";
//***HOW to set variable name dynamically***
jobs[index] = schedule.scheduleJob(scantime, function() {
console.log(scantime);
});
});
return jobs;
});
所以我想设置动态保存调度函数的变量名,这样我就可以重新调度它或稍后取消它。
工作[索引] = schedule.scheduleJob(scantime, function() { console.log(scantime); });
我怎样才能做到这一点?