Files
Checkmate/Server/controllers/queueController.js
T

63 lines
1.5 KiB
JavaScript
Raw Normal View History

2024-10-15 11:57:37 +08:00
import { handleError } from "./controllerUtils.js";
2025-01-30 00:41:31 +03:00
import ServiceRegistry from "../service/serviceRegistry.js";
import StringService from "../service/stringService.js";
2024-10-15 11:57:37 +08:00
const SERVICE_NAME = "JobQueueController";
2024-12-24 11:58:42 -08:00
class JobQueueController {
constructor(jobQueue) {
this.jobQueue = jobQueue;
2025-01-30 00:41:31 +03:00
this.stringService = ServiceRegistry.get(StringService.SERVICE_NAME);
2024-10-17 12:07:30 +08:00
}
2024-12-24 11:58:42 -08:00
getMetrics = async (req, res, next) => {
try {
const metrics = await this.jobQueue.getMetrics();
2025-01-20 11:02:55 -08:00
res.success({
2025-01-30 00:41:31 +03:00
msg: this.stringService.queueGetMetrics,
2024-12-24 11:58:42 -08:00
data: metrics,
});
} catch (error) {
next(handleError(error, SERVICE_NAME, "getMetrics"));
return;
}
};
2024-12-24 11:58:42 -08:00
getJobs = async (req, res, next) => {
try {
const jobs = await this.jobQueue.getJobStats();
2025-01-20 11:02:55 -08:00
return res.success({
2025-01-30 00:41:31 +03:00
msg: this.stringService.queueGetMetrics,
2024-12-24 11:58:42 -08:00
data: jobs,
});
} catch (error) {
next(handleError(error, SERVICE_NAME, "getJobs"));
return;
}
};
2024-12-24 11:58:42 -08:00
addJob = async (req, res, next) => {
try {
await this.jobQueue.addJob(Math.random().toString(36).substring(7));
2025-01-20 11:02:55 -08:00
return res.success({
2025-01-30 00:41:31 +03:00
msg: this.stringService.queueAddJob,
2024-12-24 11:58:42 -08:00
});
} catch (error) {
next(handleError(error, SERVICE_NAME, "addJob"));
return;
}
};
2024-12-24 11:58:42 -08:00
obliterateQueue = async (req, res, next) => {
try {
await this.jobQueue.obliterate();
2025-01-20 11:02:55 -08:00
return res.success({
2025-01-30 00:41:31 +03:00
msg: this.stringService.queueObliterate,
2025-01-19 12:04:47 -08:00
});
2024-12-24 11:58:42 -08:00
} catch (error) {
next(handleError(error, SERVICE_NAME, "obliterateQueue"));
return;
}
};
}
export default JobQueueController;