Files
Checkmate/server/controllers/queueController.js
T

83 lines
1.8 KiB
JavaScript
Raw Normal View History

import { asyncHandler } from "../utils/errorUtils.js";
2025-04-20 11:29:53 -07:00
const SERVICE_NAME = "JobQueueController";
class JobQueueController {
constructor(jobQueue, stringService) {
this.jobQueue = jobQueue;
this.stringService = stringService;
}
getMetrics = asyncHandler(
async (req, res, next) => {
2025-04-20 11:29:53 -07:00
const metrics = await this.jobQueue.getMetrics();
res.success({
msg: this.stringService.queueGetMetrics,
data: metrics,
});
},
SERVICE_NAME,
"getMetrics"
);
2025-04-20 11:29:53 -07:00
getJobs = asyncHandler(
async (req, res, next) => {
2025-05-16 14:07:47 -07:00
const jobs = await this.jobQueue.getJobs();
2025-04-20 11:29:53 -07:00
return res.success({
msg: this.stringService.queueGetJobs,
2025-04-20 11:29:53 -07:00
data: jobs,
});
},
SERVICE_NAME,
"getJobs"
);
2025-04-20 11:29:53 -07:00
getAllMetrics = asyncHandler(
async (req, res, next) => {
const jobs = await this.jobQueue.getJobs();
const metrics = await this.jobQueue.getMetrics();
return res.success({
msg: this.stringService.queueGetAllMetrics,
data: { jobs, metrics },
});
},
SERVICE_NAME,
"getAllMetrics"
);
addJob = asyncHandler(
async (req, res, next) => {
2025-04-20 11:29:53 -07:00
await this.jobQueue.addJob(Math.random().toString(36).substring(7));
return res.success({
msg: this.stringService.queueAddJob,
});
},
SERVICE_NAME,
"addJob"
);
2025-04-20 11:29:53 -07:00
flushQueue = asyncHandler(
async (req, res, next) => {
2025-05-16 14:07:47 -07:00
const result = await this.jobQueue.flushQueues();
2025-04-20 11:29:53 -07:00
return res.success({
msg: this.stringService.jobQueueFlush,
data: result,
});
},
SERVICE_NAME,
"flushQueue"
);
2025-04-20 11:29:53 -07:00
checkQueueHealth = asyncHandler(
async (req, res, next) => {
2025-04-20 11:29:53 -07:00
const stuckQueues = await this.jobQueue.checkQueueHealth();
return res.success({
msg: this.stringService.queueHealthCheck,
data: stuckQueues,
});
},
SERVICE_NAME,
"checkQueueHealth"
);
2025-04-20 11:29:53 -07:00
}
export default JobQueueController;