From 38f5c41272552249d8781615b5585ef6229ebee9 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 27 Jun 2025 13:45:18 +0800 Subject: [PATCH] implement flush --- .../SuperSimpleQueue/SuperSimpleQueue.js | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/server/service/SuperSimpleQueue/SuperSimpleQueue.js b/server/service/SuperSimpleQueue/SuperSimpleQueue.js index ec6c16ea9..578f9dd3f 100644 --- a/server/service/SuperSimpleQueue/SuperSimpleQueue.js +++ b/server/service/SuperSimpleQueue/SuperSimpleQueue.js @@ -18,15 +18,26 @@ class SuperSimpleQueue { } init = async () => { - this.scheduler = new Scheduler({ - logLevel: process.env.LOG_LEVEL, - debug: process.env.NODE_ENV, - }); - this.scheduler.start(); - this.scheduler.addTemplate("test", this.helper.getMonitorJob()); - const monitors = await this.db.getAllMonitors(); - for (const monitor of monitors) { - await this.addJob(monitor._id, monitor); + try { + this.scheduler = new Scheduler({ + logLevel: process.env.LOG_LEVEL, + debug: process.env.NODE_ENV, + }); + this.scheduler.start(); + this.scheduler.addTemplate("test", this.helper.getMonitorJob()); + const monitors = await this.db.getAllMonitors(); + for (const monitor of monitors) { + await this.addJob(monitor._id, monitor); + } + return true; + } catch (error) { + this.logger.error({ + message: "Failed to initialize SuperSimpleQueue", + service: SERVICE_NAME, + method: "init", + details: error, + }); + return false; } }; @@ -135,7 +146,12 @@ class SuperSimpleQueue { }; flushQueues = async () => { - console.log("flush not implemented"); + const stopRes = this.scheduler.stop(); + const flushRes = this.scheduler.flushJobs(); + const initRes = await this.init(); + return { + success: stopRes && flushRes && initRes, + }; }; obliterate = async () => {