add update job method
This commit is contained in:
1 parent
9a22d4a971
commit
7475dcfb21
3 files changed
+24
-6
No files matched your search
@@ -550,10 +550,8 @@ class MonitorController {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// Delete the old job(editedMonitor has the same ID as the old monitor)
|
await this.jobQueue.updateJob(editedMonitor);
|
||||||
await this.jobQueue.deleteJob(monitorBeforeEdit);
|
|
||||||
// Add the new job back to the queue
|
|
||||||
await this.jobQueue.addJob(editedMonitor._id, editedMonitor);
|
|
||||||
return res.success({
|
return res.success({
|
||||||
msg: this.stringService.monitorEdit,
|
msg: this.stringService.monitorEdit,
|
||||||
data: editedMonitor,
|
data: editedMonitor,
|
||||||
|
|||||||
@@ -188,6 +188,11 @@ class JobQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateJob(monitor) {
|
||||||
|
await this.deleteJob(monitor);
|
||||||
|
await this.addJob(monitor._id, monitor);
|
||||||
|
}
|
||||||
|
|
||||||
async getJobs() {
|
async getJobs() {
|
||||||
try {
|
try {
|
||||||
let stats = {};
|
let stats = {};
|
||||||
|
|||||||
@@ -62,10 +62,9 @@ class PulseQueue {
|
|||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "deleteJob",
|
method: "deleteJob",
|
||||||
});
|
});
|
||||||
const result = await this.pulse.cancel({
|
await this.pulse.cancel({
|
||||||
"data.monitor._id": monitor._id,
|
"data.monitor._id": monitor._id,
|
||||||
});
|
});
|
||||||
console.log(result);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pauseJob = async (monitor) => {
|
pauseJob = async (monitor) => {
|
||||||
@@ -100,6 +99,22 @@ class PulseQueue {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
updateJob = async (monitor) => {
|
||||||
|
const jobs = await this.pulse.jobs({
|
||||||
|
"data.monitor._id": monitor._id,
|
||||||
|
});
|
||||||
|
|
||||||
|
const job = jobs[0];
|
||||||
|
if (!job) {
|
||||||
|
throw new Error("Job not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
const intervalInSeconds = monitor.interval / 1000;
|
||||||
|
job.repeatEvery(`${intervalInSeconds} seconds`);
|
||||||
|
job.attrs.data.monitor = monitor;
|
||||||
|
await job.save();
|
||||||
|
};
|
||||||
|
|
||||||
shutdown = async () => {
|
shutdown = async () => {
|
||||||
this.logger.info({
|
this.logger.info({
|
||||||
message: "Shutting down JobQueue",
|
message: "Shutting down JobQueue",
|
||||||
|
|||||||
Reference in new issue
Block a user