mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-09 11:19:59 -06:00
88 lines
1.9 KiB
JavaScript
Executable File
88 lines
1.9 KiB
JavaScript
Executable File
import BaseController from "./baseController.js";
|
|
const SERVICE_NAME = "JobQueueController";
|
|
|
|
class JobQueueController extends BaseController {
|
|
static SERVICE_NAME = SERVICE_NAME;
|
|
constructor(commonDependencies, { jobQueue }) {
|
|
super(commonDependencies);
|
|
this.jobQueue = jobQueue;
|
|
}
|
|
|
|
get serviceName() {
|
|
return JobQueueController.SERVICE_NAME;
|
|
}
|
|
|
|
getMetrics = this.asyncHandler(
|
|
async (req, res) => {
|
|
const metrics = await this.jobQueue.getMetrics();
|
|
res.success({
|
|
msg: this.stringService.queueGetMetrics,
|
|
data: metrics,
|
|
});
|
|
},
|
|
SERVICE_NAME,
|
|
"getMetrics"
|
|
);
|
|
|
|
getJobs = this.asyncHandler(
|
|
async (req, res) => {
|
|
const jobs = await this.jobQueue.getJobs();
|
|
return res.success({
|
|
msg: this.stringService.queueGetJobs,
|
|
data: jobs,
|
|
});
|
|
},
|
|
SERVICE_NAME,
|
|
"getJobs"
|
|
);
|
|
|
|
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"
|
|
);
|
|
|
|
addJob = this.asyncHandler(
|
|
async (req, res) => {
|
|
await this.jobQueue.addJob(Math.random().toString(36).substring(7));
|
|
return res.success({
|
|
msg: this.stringService.queueAddJob,
|
|
});
|
|
},
|
|
SERVICE_NAME,
|
|
"addJob"
|
|
);
|
|
|
|
flushQueue = this.asyncHandler(
|
|
async (req, res) => {
|
|
const result = await this.jobQueue.flushQueues();
|
|
return res.success({
|
|
msg: this.stringService.jobQueueFlush,
|
|
data: result,
|
|
});
|
|
},
|
|
SERVICE_NAME,
|
|
"flushQueue"
|
|
);
|
|
|
|
checkQueueHealth = this.asyncHandler(
|
|
async (req, res) => {
|
|
const stuckQueues = await this.jobQueue.checkQueueHealth();
|
|
return res.success({
|
|
msg: this.stringService.queueHealthCheck,
|
|
data: stuckQueues,
|
|
});
|
|
},
|
|
SERVICE_NAME,
|
|
"checkQueueHealth"
|
|
);
|
|
}
|
|
export default JobQueueController;
|