Files
Checkmate/Server/controllers/queueController.js
T

61 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-10-15 11:57:37 +08:00
import { handleError } from "./controllerUtils.js";
2024-12-24 11:58:42 -08:00
import { successMessages } from "../utils/messages.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;
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({
2024-12-24 11:58:42 -08:00
msg: successMessages.QUEUE_GET_METRICS,
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({
2024-12-24 11:58:42 -08:00
msg: successMessages.QUEUE_GET_METRICS,
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({
2024-12-24 11:58:42 -08:00
msg: successMessages.QUEUE_ADD_JOB,
});
} 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-19 12:04:47 -08:00
msg: successMessages.QUEUE_OBLITERATE,
});
2024-12-24 11:58:42 -08:00
} catch (error) {
next(handleError(error, SERVICE_NAME, "obliterateQueue"));
return;
}
};
}
export default JobQueueController;