add an error service, base controller

This commit is contained in:
Alex Holliday committed 2025-07-24 15:06:46 -07:00
1 parent 0cfe9d60fb
commit ddf3e8251d
20 files changed
+412 -301

No files matched your search

+17 -16
View File
@@ -1,15 +1,16 @@
import { asyncHandler } from "../utils/errorUtils.js";
import BaseController from "./baseController.js";
const SERVICE_NAME = "JobQueueController";
class JobQueueController {
constructor(jobQueue, stringService) {
class JobQueueController extends BaseController {
constructor({ jobQueue, stringService, errorService }) {
super();
this.jobQueue = jobQueue;
this.stringService = stringService;
this.errorService = errorService;
}
getMetrics = asyncHandler(
async (req, res, next) => {
getMetrics = this.asyncHandler(
async (req, res) => {
const metrics = await this.jobQueue.getMetrics();
res.success({
msg: this.stringService.queueGetMetrics,
@@ -20,8 +21,8 @@ class JobQueueController {
"getMetrics"
);
getJobs = asyncHandler(
async (req, res, next) => {
getJobs = this.asyncHandler(
async (req, res) => {
const jobs = await this.jobQueue.getJobs();
return res.success({
msg: this.stringService.queueGetJobs,
@@ -32,8 +33,8 @@ class JobQueueController {
"getJobs"
);
getAllMetrics = asyncHandler(
async (req, res, next) => {
getAllMetrics = this.asyncHandler(
async (req, res) => {
const jobs = await this.jobQueue.getJobs();
const metrics = await this.jobQueue.getMetrics();
return res.success({
@@ -45,8 +46,8 @@ class JobQueueController {
"getAllMetrics"
);
addJob = asyncHandler(
async (req, res, next) => {
addJob = this.asyncHandler(
async (req, res) => {
await this.jobQueue.addJob(Math.random().toString(36).substring(7));
return res.success({
msg: this.stringService.queueAddJob,
@@ -56,8 +57,8 @@ class JobQueueController {
"addJob"
);
flushQueue = asyncHandler(
async (req, res, next) => {
flushQueue = this.asyncHandler(
async (req, res) => {
const result = await this.jobQueue.flushQueues();
return res.success({
msg: this.stringService.jobQueueFlush,
@@ -68,8 +69,8 @@ class JobQueueController {
"flushQueue"
);
checkQueueHealth = asyncHandler(
async (req, res, next) => {
checkQueueHealth = this.asyncHandler(
async (req, res) => {
const stuckQueues = await this.jobQueue.checkQueueHealth();
return res.success({
msg: this.stringService.queueHealthCheck,