提问人:flow24 提问时间:11/14/2023 最后编辑:flow24 更新时间:11/14/2023 访问量:8
议程 js - 更新特定作业不起作用
Agenda js - updating specific job doesn't work
问:
尝试使用以前的帖子,但没有解决方案。
我得到了一系列工作,对于我执行的每一项工作:scheduleJob
private constructor(mongoUri: string) {
const isDev = process.env.NODE_ENV === 'development';
this.agenda = new Agenda({
db: {
address: mongoUri,
collection: isDev ? 'agenda-dev' : 'agenda-prod',
},
});
}
private defineJob(name: string) {
if (!this.agenda._definitions[name]) {
this.agenda.define(name, async (job: AgendaJob) => {
const { job: currentJob } = job.attrs.data;
//... business logic
});
}
}
private async scheduleJob(job: JobDocument) {
const { isActive, schedule, name, _id } = job;
if (isActive) {
this.defineJob(name);
const agendaJob = this.agenda.create(name, { job });
await agendaJob
.unique({ 'data.job._id': _id })
.repeatEvery(schedule)
.save();
console.log(
`Job ${name} with ID ${_id} is scheduled to run every ${schedule}.`
);
} else{
await this.agenda.cancel({ name });
console.log(`Job ${name} with ID ${_id} has been canceled.`);
}
}
这不会更新作业。 我错过了什么?
答: 暂无答案
评论