gpt4 book ai didi

How to get all the jobs scheduled with different names in node-schedule?(如何在node-Schedule中以不同的名称调度所有作业?)

转载 作者:bug小助手 更新时间:2023-10-24 20:20:18 36 4
gpt4 key购买 nike



I want to get the list of all the jobs that are scheduled by node-schedule

我想获取所有按节点调度调度的作业的列表



 var scheduleIds = schedule.scheduleJob(scheduleId,rule, function() {
console.log("HELLO")
})


here scheduleId is a unique key and there are multiple jobs running with different names. How can I find a job from its name and cancel it?

其中,ScheduleID是唯一键,并且有多个作业正在以不同的名称运行。我如何根据职务名称找到职务并将其取消?


更多回答
优秀答案推荐

var schedule = require('node-schedule');
var scheduleIds = schedule.scheduleJob(scheduleId,rule, function() {
console.log("HELLO")
})


The schedule object that is created contains all the names of the jobs that are scheduled.

创建的调度对象包含已调度作业的所有名称。



I had the same query and this is what worked for me. I am using [node-schedule v2.1.0][1] and this is 8y11m after the question was posted. So I am not sure if the API has changed a bit since the above answers.

我也有同样的疑问,这就是对我有效的方法。我正在使用[node-Schedule v2.1.0][1],这是问题发布后的8年11月。因此,我不确定在回答上述问题后,API是否发生了一些变化。


To get access to scheduled jobs, use code like below:

要获得对计划作业的访问权限,请使用如下代码:




const schedule = require('node-schedule'); // import module
const {scheduledJobs} = schedule; // get access to scheduled jobs
console.log({scheduledJobs}); // prints {scheduledJobs: {<job1 object>}, {job2 object>}, ...} to console




To access a specific job by name, use code similar to this:

要按名称访问特定作业,请使用类似以下内容的代码:




console.log(scheduledJobs['hello123']); // prints Job object by name "hello123", if it exists, to console




The above snippet assumes that a job with name 'hello123' has been already scheduled. To cancel this job, one can use a code similar to this:

上面的代码片段假定已经调度了名为‘hello123’的作业。要取消此作业,可以使用类似以下代码的代码:




const hello123job = scheduledJobs['hello123']; // returns Job object corresponding to job with name 'hello123'
const status = schedule.cancelJob(hello123job); // Cancels the job and returns Boolean true on success




更多回答

When I console.log the schedule object, the result is this: { [Function: scheduleJob] bindAsync: { [Function] __isPromisified__: true }, toStringAsync: { [Function] __isPromisified__: true }, callAsync: { [Function] __isPromisified__: true }, applyAsync: { [Function] __isPromisified__: true } } It'd be great if you tell how to get those names and use them?

当我Console.log Schedule对象时,结果是:{[Function:ScheduleJob]bindAsync:{[Function]__isPromisified__:True},toStringAsync:{[Function]__isPromisified__:True},call Async:{[Function]__isPromisified__:True},applyAsync:{[Function]__isPromisified__:True}如果你告诉如何获取并使用这些名称,那将是很棒的?

schedule.scheduledJobs is an array that will show you all the jobs that are scheduled. Just do this console.log(schedule.scheduledJobs)

Schedule.SchedJobs是一个数组,它将显示所有已调度的作业。只需执行下面的sole.log(Schedule.SchededJobs)

scheduledJobs is (at least now), an object: {[jobName: string]: schedule.Job}

scheduledJobs是(至少现在是)一个对象:{[jobName:string]:schedule.Job}

36 4 0