Add job queue to docs
This commit is contained in:
1 parent
35d2d8301e
commit
d55119c28d
5 files changed
+176
-7
No files matched your search
@@ -41,7 +41,7 @@ const addJob = async (req, res, next) => {
|
|||||||
const obliterateQueue = async (req, res, next) => {
|
const obliterateQueue = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const obliterated = await req.jobQueue.obliterate();
|
const obliterated = await req.jobQueue.obliterate();
|
||||||
return res.status(200).send("Obliterated jobs");
|
return res.status(200).send("Obliterated queue");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||||
error.method === undefined ? (error.method = "obliterateQueue") : null;
|
error.method === undefined ? (error.method = "obliterateQueue") : null;
|
||||||
|
|||||||
+1
-2
@@ -84,8 +84,7 @@ const startApp = async () => {
|
|||||||
app.use("/api/v1/monitors", verifyJWT, monitorRouter);
|
app.use("/api/v1/monitors", verifyJWT, monitorRouter);
|
||||||
app.use("/api/v1/checks", verifyJWT, checkRouter);
|
app.use("/api/v1/checks", verifyJWT, checkRouter);
|
||||||
app.use("/api/v1/maintenance-window", verifyJWT, maintenanceWindowRouter);
|
app.use("/api/v1/maintenance-window", verifyJWT, maintenanceWindowRouter);
|
||||||
//Temporary route for testing, remove later
|
app.use("/api/v1/queue", verifyJWT, queueRouter);
|
||||||
app.use("/api/v1/job", queueRouter);
|
|
||||||
|
|
||||||
//health check
|
//health check
|
||||||
app.use("/api/v1/healthy", (req, res) => {
|
app.use("/api/v1/healthy", (req, res) => {
|
||||||
|
|||||||
@@ -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": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ const queueController = require("../controllers/queueController");
|
|||||||
router.get("/metrics", queueController.getMetrics);
|
router.get("/metrics", queueController.getMetrics);
|
||||||
|
|
||||||
// Get Jobs
|
// Get Jobs
|
||||||
router.get("/", queueController.getJobs);
|
router.get("/jobs", queueController.getJobs);
|
||||||
|
|
||||||
// Add Job
|
// Add Job
|
||||||
router.post("/", queueController.addJob);
|
router.post("/jobs", queueController.addJob);
|
||||||
|
|
||||||
// Obliterate Queue
|
// Obliterate Queue
|
||||||
router.post("/obliterate", queueController.obliterateQueue);
|
router.post("/obliterate", queueController.obliterateQueue);
|
||||||
|
|||||||
@@ -240,12 +240,12 @@ class JobQueue {
|
|||||||
*/
|
*/
|
||||||
async addJob(jobName, payload) {
|
async addJob(jobName, payload) {
|
||||||
try {
|
try {
|
||||||
console.log("Adding job", payload.url);
|
console.log("Adding job", payload?.url ?? "No URL");
|
||||||
// Execute job immediately
|
// Execute job immediately
|
||||||
await this.queue.add(jobName, payload);
|
await this.queue.add(jobName, payload);
|
||||||
await this.queue.add(jobName, payload, {
|
await this.queue.add(jobName, payload, {
|
||||||
repeat: {
|
repeat: {
|
||||||
every: payload.interval,
|
every: payload?.interval ?? 60000,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const workerStats = await this.getWorkerStats();
|
const workerStats = await this.getWorkerStats();
|
||||||
|
|||||||
Reference in new issue
Block a user