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,
|
|
|
|
|
});
|
2025-07-15 16:33:35 -07:00
|
|
|
},
|
|
|
|
|
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({
|
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-24 15:06:46 -07:00
|
|
|
getAllMetrics = this.asyncHandler(
|
|
|
|
|
async (req, res) => {
|
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-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,
|
|
|
|
|
});
|
2025-07-15 16:33:35 -07:00
|
|
|
},
|
|
|
|
|
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,
|
|
|
|
|
});
|
2025-07-15 16:33:35 -07:00
|
|
|
},
|
|
|
|
|
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,
|
|
|
|
|
});
|
2025-07-15 16:33:35 -07:00
|
|
|
},
|
|
|
|
|
SERVICE_NAME,
|
|
|
|
|
"checkQueueHealth"
|
|
|
|
|
);
|
2025-04-20 11:29:53 -07:00
|
|
|
}
|
|
|
|
|
export default JobQueueController;
|