From 2fda99dbeff2ba04fcc0b65335f1b83bf72a921e Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 28 Oct 2024 18:09:00 +0800 Subject: [PATCH] Update jobQueue JSdocs --- Server/service/jobQueue.js | 47 +++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/Server/service/jobQueue.js b/Server/service/jobQueue.js index 70f63e74f..3369d815a 100644 --- a/Server/service/jobQueue.js +++ b/Server/service/jobQueue.js @@ -11,10 +11,15 @@ const SERVICE_NAME = "JobQueue"; */ class JobQueue { /** - * Constructs a new JobQueue - * @constructor - * @param {SettingsService} settingsService - The settings service - * @throws {Error} + * @class JobQueue + * @classdesc Manages job queue and workers. + * + * @param {Object} statusService - Service for handling status updates. + * @param {Object} notificationService - Service for handling notifications. + * @param {Object} settingsService - Service for retrieving settings. + * @param {Object} logger - Logger for logging information. + * @param {Function} Queue - Queue constructor. + * @param {Function} Worker - Worker constructor. */ constructor( statusService, @@ -46,11 +51,18 @@ class JobQueue { } /** - * Static factory method to create a JobQueue - * @static - * @async - * @returns {Promise} - Returns a new JobQueue + * Creates and initializes a JobQueue instance. * + * @param {Object} db - Database service for accessing monitors. + * @param {Object} networkService - Service for network operations. + * @param {Object} statusService - Service for handling status updates. + * @param {Object} notificationService - Service for handling notifications. + * @param {Object} settingsService - Service for retrieving settings. + * @param {Object} logger - Logger for logging information. + * @param {Function} Queue - Queue constructor. + * @param {Function} Worker - Worker constructor. + * @returns {Promise} - The initialized JobQueue instance. + * @throws {Error} - Throws an error if initialization fails. */ static async createJobQueue( db, @@ -89,6 +101,13 @@ class JobQueue { } } + /** + * Checks if the given monitor is in a maintenance window. + * + * @param {string} monitorId - The ID of the monitor to check. + * @returns {Promise} - Returns true if the monitor is in a maintenance window, otherwise false. + * @throws {Error} - Throws an error if the database query fails. + */ async isInMaintenanceWindow(monitorId) { const maintenanceWindows = await this.db.getMaintenanceWindowsByMonitorId(monitorId); // Check for active maintenance window: @@ -286,6 +305,12 @@ class JobQueue { } } + /** + * Retrieves the statistics of jobs and workers. + * + * @returns {Promise} - An object containing job statistics and the number of workers. + * @throws {Error} - Throws an error if the job statistics retrieval fails. + */ async getJobStats() { try { const jobs = await this.queue.getJobs(); @@ -366,6 +391,12 @@ class JobQueue { } } + /** + * Retrieves the metrics of the job queue. + * + * @returns {Promise} - An object containing various job queue metrics. + * @throws {Error} - Throws an error if the metrics retrieval fails. + */ async getMetrics() { try { const metrics = {