我有一个网络刮刀,是运行在前景使用木偶。我需要杀死木偶师,这是一个异步函数(不是NODE.JS进程)。我为什么要杀了它?因为这个web抓取需要每一天执行一次,所以我想杀死它,因为出于某种原因(如果还在运行),相同的函数被执行了很多次。
这是我的代码:
class Webscraping {
start(){
this.scrapeWithPuppeteer()
this.runPuppeteerAgainDaily()
}
scrapeWithPuppeteer() {
// asynchronous code
}
runPuppeteerAgainDaily() {
// I'm usingthe npm package "node-schedule"
schedule.scheduleJob('5 52 21 * * *', () => {
// KILL CURRENT this.scrapeWithPuppeteer()
// and then
this.scrapeWithPuppeteer()
})
}
}
let webscraper = new Webscraping()
webscraping.start()发布于 2019-08-30 02:25:05
schedule.scheduleJob是节点调度 NPM模块的一部分.
如果你看这些文档,https://www.npmjs.com/package/node-schedule
可以看到,下面的代码取消了计划的作业:
job.cancel();换句话说,跟踪你的工作,这样你就可以用上面的函数取消它。
https://stackoverflow.com/questions/57719721
复制相似问题