This commit is contained in:
Alex Holliday
2026-01-09 15:07:02 -08:00
parent 64320c7aca
commit 3f631ff382
3 changed files with 89 additions and 90 deletions
+1 -3
View File
@@ -46,9 +46,7 @@ export const initializeControllers = (services) => {
settingsService: services.settingsService,
maintenanceWindowService: services.maintenanceWindowService,
});
controllers.queueController = new QueueController(commonDependencies, {
jobQueue: services.jobQueue,
});
controllers.queueController = new QueueController(services.jobQueue);
controllers.logController = new LogController(commonDependencies);
controllers.statusPageController = new StatusPageController(commonDependencies);
controllers.notificationController = new NotificationController(services.notificationService, services.db);
@@ -1,87 +0,0 @@
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;
+88
View File
@@ -0,0 +1,88 @@
import { Request, Response, NextFunction } from "express";
const SERVICE_NAME = "JobQueueController";
class JobQueueController {
static SERVICE_NAME = SERVICE_NAME;
private jobQueue: any;
constructor(jobQueue: any) {
this.jobQueue = jobQueue;
}
get serviceName() {
return JobQueueController.SERVICE_NAME;
}
getMetrics = async (req: Request, res: Response, next: NextFunction) => {
try {
const metrics = await this.jobQueue.getMetrics();
res.status(200).json({
msg: "Queue metrics fetched successfully",
data: metrics,
});
} catch (error) {
next(error);
}
};
getJobs = async (req: Request, res: Response, next: NextFunction) => {
try {
const jobs = await this.jobQueue.getJobs();
return res.status(200).json({
msg: "Queue jobs fetched successfully",
data: jobs,
});
} catch (error) {
next(error);
}
};
getAllMetrics = async (req: Request, res: Response, next: NextFunction) => {
try {
const jobs = await this.jobQueue.getJobs();
const metrics = await this.jobQueue.getMetrics();
return res.status(200).json({
msg: "Queue metrics fetched successfully",
data: { jobs, metrics },
});
} catch (error) {
next(error);
}
};
addJob = async (req: Request, res: Response, next: NextFunction) => {
try {
await this.jobQueue.addJob(Math.random().toString(36).substring(7));
return res.status(200).json({
msg: "Job added to queue successfully",
});
} catch (error) {
next(error);
}
};
flushQueue = async (req: Request, res: Response, next: NextFunction) => {
try {
const result = await this.jobQueue.flushQueues();
return res.status(200).json({
msg: "Queue flushed successfully",
data: result,
});
} catch (error) {
next(error);
}
};
checkQueueHealth = async (req: Request, res: Response, next: NextFunction) => {
try {
const stuckQueues = await this.jobQueue.checkQueueHealth();
return res.status(200).json({
msg: "Queue health checked successfully",
data: stuckQueues,
});
} catch (error) {
next(error);
}
};
}
export default JobQueueController;