首页 > 解决方案 > 这些 Node 生成的 CronJobs 存储在哪里?

问题描述

我使用以下代码使用cron创建了 CronJobs ,但是我找不到它们来销毁它们。在 Debian BullsEye 上,我检查了 /etc/crontab、/etc/cron.d、/etc/cron.daily、/etc/cron.weekly、/etc/cron.monthly 并没有任何内容。

此进程在 www-data 下运行

        new cronjob('* ' + sMarr[i] + ' ' + sHarr[i] + ' * * *', function(x) {
      
          shell.exec('ffmpeg -hide_banner -loglevel warning -i '+iUarr[x]+' -c:a aac -t 00:'+dMarr[x]+':'+dSarr[x]+' -f hls /mnt/streamlinks/'+outputName+'.m3u8&', {async:true});
        }.bind(null, i), null,  true, 'Europe/London').start();
        console.log("made cron job");
      }catch{
        console.log("Error creating cronjob");  
      }

提前致谢。

标签: node.jscron

解决方案


这些 cron 作业是在内存中创建的,它们不是在系统级别创建的。这允许模块在不同的操作系统(例如 Windows)上工作。

创建作业时,您可以保留对它的引用,然后使用 job.stop() 随时停止它。

const CronJob = require('cron').CronJob;
const job = new CronJob('* * * * * *', function() {
    console.log('Sample cron job...');
}, null, false);

// Start the cron job...
job.start();

setTimeout(() => {
    console.log("Stopping cron job..");
    // Kill the cron job
    job.stop();
}, 10000)

推荐阅读