Add job queue to docs

This commit is contained in:
Alex Holliday
2024-09-25 12:55:31 +08:00
parent 35d2d8301e
commit d55119c28d
5 changed files with 176 additions and 7 deletions
+1 -1
View File
@@ -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;
+1 -2
View File
@@ -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) => {
+170
View File
@@ -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": []
}
]
}
}
},
+2 -2
View File
@@ -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);
+2 -2
View File
@@ -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();