Files
Checkmate/server/controllers/queueController.js
T

82 lines
1.8 KiB
JavaScript
Raw Normal View History

2025-07-24 15:06:46 -07:00
import BaseController from "./baseController.js";
2025-04-20 11:29:53 -07:00
const SERVICE_NAME = "JobQueueController";
2025-07-24 15:06:46 -07:00
class JobQueueController extends BaseController {
2025-07-25 10:16:29 -07:00
constructor(commonDependencies, { jobQueue }) {
super(commonDependencies);
2025-04-20 11:29:53 -07:00
this.jobQueue = jobQueue;
}
2025-07-24 15:06:46 -07:00
getMetrics = this.asyncHandler(
async (req, res) => {
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
2025-07-24 15:06:46 -07:00
getJobs = this.asyncHandler(
async (req, res) => {
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
2025-07-24 15:06:46 -07:00
getAllMetrics = this.asyncHandler(
async (req, res) => {
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"
);
2025-07-24 15:06:46 -07:00
addJob = this.asyncHandler(
async (req, res) => {
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
2025-07-24 15:06:46 -07:00
flushQueue = this.asyncHandler(
async (req, res) => {
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
2025-07-24 15:06:46 -07:00
checkQueueHealth = this.asyncHandler(
async (req, res) => {
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;