diff --git a/Server/controllers/queueController.js b/Server/controllers/queueController.js index 5960552c4..bbb3304ee 100644 --- a/Server/controllers/queueController.js +++ b/Server/controllers/queueController.js @@ -41,7 +41,7 @@ const addJob = async (req, res, next) => { const obliterateQueue = async (req, res, next) => { try { const obliterated = await req.jobQueue.obliterate(); - return res.status(200).send("Obliterated jobs"); + return res.status(200).send("Obliterated queue"); } catch (error) { error.service === undefined ? (error.service = SERVICE_NAME) : null; error.method === undefined ? (error.method = "obliterateQueue") : null; diff --git a/Server/index.js b/Server/index.js index 25f70a532..05c9d3059 100644 --- a/Server/index.js +++ b/Server/index.js @@ -84,8 +84,7 @@ const startApp = async () => { app.use("/api/v1/monitors", verifyJWT, monitorRouter); app.use("/api/v1/checks", verifyJWT, checkRouter); app.use("/api/v1/maintenance-window", verifyJWT, maintenanceWindowRouter); - //Temporary route for testing, remove later - app.use("/api/v1/job", queueRouter); + app.use("/api/v1/queue", verifyJWT, queueRouter); //health check app.use("/api/v1/healthy", (req, res) => { diff --git a/Server/openapi.json b/Server/openapi.json index a7de094f4..6a19bde13 100644 --- a/Server/openapi.json +++ b/Server/openapi.json @@ -1875,6 +1875,176 @@ } ] } + }, + "/queue/jobs": { + "get": { + "tags": ["queue"], + "description": "Get all jobs in queue", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SuccessResponse" + } + } + } + }, + "422": { + "description": "Unprocessable Content", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + } + }, + "security": [ + { + "bearerAuth": [] + } + ] + }, + "post": { + "tags": ["queue"], + "description": "Create a new job. Useful for testing scaling workers", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SuccessResponse" + } + } + } + }, + "422": { + "description": "Unprocessable Content", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + } + }, + "security": [ + { + "bearerAuth": [] + } + ] + } + }, + "/queue/metrics": { + "get": { + "tags": ["queue"], + "description": "Get queue metrics", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SuccessResponse" + } + } + } + }, + "422": { + "description": "Unprocessable Content", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + } + }, + "security": [ + { + "bearerAuth": [] + } + ] + } + }, + "/queue/obliterate": { + "post": { + "tags": ["queue"], + "description": "Obliterate job queue", + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SuccessResponse" + } + } + } + }, + "422": { + "description": "Unprocessable Content", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "500": { + "description": "Internal Server Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + } + }, + "security": [ + { + "bearerAuth": [] + } + ] + } } }, diff --git a/Server/routes/queueRoute.js b/Server/routes/queueRoute.js index cbc68df6d..b14eaa2b0 100644 --- a/Server/routes/queueRoute.js +++ b/Server/routes/queueRoute.js @@ -4,10 +4,10 @@ const queueController = require("../controllers/queueController"); router.get("/metrics", queueController.getMetrics); // Get Jobs -router.get("/", queueController.getJobs); +router.get("/jobs", queueController.getJobs); // Add Job -router.post("/", queueController.addJob); +router.post("/jobs", queueController.addJob); // Obliterate Queue router.post("/obliterate", queueController.obliterateQueue); diff --git a/Server/service/jobQueue.js b/Server/service/jobQueue.js index 5d58dd4a4..5a6d3e8e0 100644 --- a/Server/service/jobQueue.js +++ b/Server/service/jobQueue.js @@ -240,12 +240,12 @@ class JobQueue { */ async addJob(jobName, payload) { try { - console.log("Adding job", payload.url); + console.log("Adding job", payload?.url ?? "No URL"); // Execute job immediately await this.queue.add(jobName, payload); await this.queue.add(jobName, payload, { repeat: { - every: payload.interval, + every: payload?.interval ?? 60000, }, }); const workerStats = await this.getWorkerStats();