2025-07-15 16:33:35 -07:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-15 16:33:35 -07:00
|
|
|
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,
|
|
|
|
|
});
|
2025-07-15 16:33:35 -07:00
|
|
|
},
|
|
|
|
|
SERVICE_NAME,
|
|
|
|
|
"getMetrics"
|
|
|
|
|
);
|
2025-04-20 11:29:53 -07:00
|
|
|
|
2025-07-15 16:33:35 -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({
|
2025-06-20 14:29:27 +08:00
|
|
|
msg: this.stringService.queueGetJobs,
|
2025-04-20 11:29:53 -07:00
|
|
|
data: jobs,
|
|
|
|
|
});
|
2025-07-15 16:33:35 -07:00
|
|
|
},
|
|
|
|
|
SERVICE_NAME,
|
|
|
|
|
"getJobs"
|
|
|
|
|
);
|
2025-04-20 11:29:53 -07:00
|
|
|
|
2025-07-15 16:33:35 -07:00
|
|
|
getAllMetrics = asyncHandler(
|
|
|
|
|
async (req, res, next) => {
|
2025-06-20 14:29:27 +08:00
|
|
|
const jobs = await this.jobQueue.getJobs();
|
|
|
|
|
const metrics = await this.jobQueue.getMetrics();
|
|
|
|
|
return res.success({
|
|
|
|
|
msg: this.stringService.queueGetAllMetrics,
|
|
|
|
|
data: { jobs, metrics },
|
|
|
|
|
});
|
2025-07-15 16:33:35 -07:00
|
|
|
},
|
|
|
|
|
SERVICE_NAME,
|
|
|
|
|
"getAllMetrics"
|
|
|
|
|
);
|
2025-06-20 14:29:27 +08:00
|
|
|
|
2025-07-15 16:33:35 -07:00
|
|
|
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,
|
|
|
|
|
});
|
2025-07-15 16:33:35 -07:00
|
|
|
},
|
|
|
|
|
SERVICE_NAME,
|
|
|
|
|
"addJob"
|
|
|
|
|
);
|
2025-04-20 11:29:53 -07:00
|
|
|
|
2025-07-15 16:33:35 -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,
|
|
|
|
|
});
|
2025-07-15 16:33:35 -07:00
|
|
|
},
|
|
|
|
|
SERVICE_NAME,
|
|
|
|
|
"flushQueue"
|
|
|
|
|
);
|
2025-04-20 11:29:53 -07:00
|
|
|
|
2025-07-15 16:33:35 -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,
|
|
|
|
|
});
|
2025-07-15 16:33:35 -07:00
|
|
|
},
|
|
|
|
|
SERVICE_NAME,
|
|
|
|
|
"checkQueueHealth"
|
|
|
|
|
);
|
2025-04-20 11:29:53 -07:00
|
|
|
}
|
|
|
|
|
export default JobQueueController;
|