2024-09-15 12:19:39 +08:00
|
|
|
const SERVICE_NAME = "JobQueueController";
|
2024-06-05 12:29:01 -07:00
|
|
|
|
2024-08-15 14:13:12 -07:00
|
|
|
const getMetrics = async (req, res, next) => {
|
|
|
|
|
try {
|
|
|
|
|
const metrics = await req.jobQueue.getMetrics();
|
|
|
|
|
res
|
|
|
|
|
.status(200)
|
|
|
|
|
.json({ success: true, msg: "Metrics retrieved", data: metrics });
|
|
|
|
|
} catch (error) {
|
2024-09-15 12:19:39 +08:00
|
|
|
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
|
|
|
|
error.method === undefined ? (error.method = "getMetrics") : null;
|
2024-08-15 14:13:12 -07:00
|
|
|
next(error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-05 12:29:01 -07:00
|
|
|
const getJobs = async (req, res, next) => {
|
|
|
|
|
try {
|
2024-08-06 13:52:48 -07:00
|
|
|
const jobs = await req.jobQueue.getJobStats();
|
2024-06-05 12:29:01 -07:00
|
|
|
return res.status(200).json({ jobs });
|
|
|
|
|
} catch (error) {
|
2024-09-15 12:19:39 +08:00
|
|
|
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
|
|
|
|
error.method === undefined ? (error.method = "getJobs") : null;
|
2024-06-05 12:29:01 -07:00
|
|
|
next(error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const addJob = async (req, res, next) => {
|
|
|
|
|
try {
|
|
|
|
|
await req.jobQueue.addJob(Math.random().toString(36).substring(7));
|
|
|
|
|
return res.send("Added job");
|
|
|
|
|
} catch (error) {
|
2024-09-15 12:19:39 +08:00
|
|
|
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
|
|
|
|
error.method === undefined ? (error.method = "addJob") : null;
|
2024-06-05 12:29:01 -07:00
|
|
|
next(error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const obliterateQueue = async (req, res, next) => {
|
|
|
|
|
try {
|
|
|
|
|
const obliterated = await req.jobQueue.obliterate();
|
2024-09-25 12:55:31 +08:00
|
|
|
return res.status(200).send("Obliterated queue");
|
2024-06-05 12:29:01 -07:00
|
|
|
} catch (error) {
|
2024-09-15 12:19:39 +08:00
|
|
|
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
|
|
|
|
error.method === undefined ? (error.method = "obliterateQueue") : null;
|
2024-06-05 12:29:01 -07:00
|
|
|
next(error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
2024-08-15 14:13:12 -07:00
|
|
|
getMetrics,
|
2024-06-05 12:29:01 -07:00
|
|
|
getJobs,
|
|
|
|
|
addJob,
|
|
|
|
|
obliterateQueue,
|
|
|
|
|
};
|