refactor server

This commit is contained in:
Alex Holliday committed 2025-07-25 15:15:14 -07:00
1 parent 6cb538ce69
commit acc910cbc0
48 files changed
+584 -650

No files matched your search

@@ -23,6 +23,10 @@ class JobQueue {
this.workers = [];
}
get serviceName() {
return JobQueue.SERVICE_NAME;
}
static async create({ db, jobQueueHelper, logger, stringService }) {
const instance = new JobQueue({ db, jobQueueHelper, logger, stringService });
await instance.init();
@@ -1,6 +1,8 @@
const SERVICE_NAME = "JobQueueHelper";
class JobQueueHelper {
static SERVICE_NAME = SERVICE_NAME;
constructor({ redisService, Queue, Worker, logger, db, networkService, statusService, notificationService }) {
this.db = db;
this.redisService = redisService;
@@ -12,6 +14,10 @@ class JobQueueHelper {
this.notificationService = notificationService;
}
get serviceName() {
return JobQueueHelper.SERVICE_NAME;
}
createQueue(queueName) {
const connection = this.redisService.getNewConnection();
const q = new this.Queue(queueName, {
@@ -1,6 +1,6 @@
import { Pulse } from "@pulsecron/pulse";
const SERVICE_NAME = "PulseQueue";
const SERVICE_NAME = "JobQueue";
class PulseQueue {
static SERVICE_NAME = SERVICE_NAME;
@@ -11,6 +11,10 @@ class PulseQueue {
this.logger = logger;
}
get serviceName() {
return PulseQueue.SERVICE_NAME;
}
static async create({ appSettings, db, pulseQueueHelper, logger }) {
const instance = new PulseQueue({ appSettings, db, pulseQueueHelper, logger });
await instance.init();
@@ -1,6 +1,8 @@
const SERVICE_NAME = "PulseQueueHelper";
class PulseQueueHelper {
static SERVICE_NAME = SERVICE_NAME;
constructor({ db, logger, networkService, statusService, notificationService }) {
this.db = db;
this.logger = logger;
@@ -9,6 +11,10 @@ class PulseQueueHelper {
this.notificationService = notificationService;
}
get serviceName() {
return PulseQueueHelper.SERVICE_NAME;
}
getMonitorJob = () => {
return async (job) => {
try {
@@ -1,5 +1,5 @@
import Scheduler from "super-simple-scheduler";
const SERVICE_NAME = "SuperSimpleQueue";
const SERVICE_NAME = "JobQueue";
class SuperSimpleQueue {
static SERVICE_NAME = SERVICE_NAME;
@@ -11,6 +11,10 @@ class SuperSimpleQueue {
this.helper = helper;
}
get serviceName() {
return SuperSimpleQueue.SERVICE_NAME;
}
static async create({ appSettings, db, logger, helper }) {
const instance = new SuperSimpleQueue({ appSettings, db, logger, helper });
await instance.init();
@@ -1,6 +1,7 @@
const SERVICE_NAME = "SuperSimpleQueueHelper";
const SERVICE_NAME = "JobQueueHelper";
class SuperSimpleQueueHelper {
static SERVICE_NAME = SERVICE_NAME;
constructor({ db, logger, networkService, statusService, notificationService }) {
this.db = db;
this.logger = logger;
@@ -9,6 +10,10 @@ class SuperSimpleQueueHelper {
this.notificationService = notificationService;
}
get serviceName() {
return SuperSimpleQueueHelper.SERVICE_NAME;
}
getMonitorJob = () => {
return async (monitor) => {
try {
@@ -10,6 +10,7 @@ const TYPE_MAP = {
};
class BufferService {
static SERVICE_NAME = SERVICE_NAME;
constructor({ db, logger }) {
this.db = db;
this.logger = logger;
@@ -32,7 +33,10 @@ class BufferService {
method: "constructor",
});
}
static SERVICE_NAME = SERVICE_NAME;
get serviceName() {
return BufferService.SERVICE_NAME;
}
addToBuffer({ check, type }) {
try {
@@ -33,6 +33,10 @@ class EmailService {
this.init();
}
get serviceName() {
return EmailService.SERVICE_NAME;
}
init = async () => {
/**
* Loads an email template from the filesystem.
@@ -42,7 +46,7 @@ class EmailService {
*/
this.loadTemplate = (templateName) => {
try {
const templatePath = this.path.join(__dirname, `../templates/${templateName}.mjml`);
const templatePath = this.path.join(__dirname, `../../templates/${templateName}.mjml`);
const templateContent = this.fs.readFileSync(templatePath, "utf8");
return this.compile(templateContent);
} catch (error) {
@@ -55,9 +55,12 @@ class BadRequestError extends AppError {
const SERVICE_NAME = "ErrorService";
class ErrorService {
static SERVICE_NAME = SERVICE_NAME;
constructor() {}
get serviceName() {
return ErrorService.SERVICE_NAME;
}
createError = (message, status = 500, service = null, method = null, details = null) => {
return new AppError(message, status, service, method, details);
};
@@ -36,6 +36,10 @@ class NetworkService {
this.settingsService = settingsService;
}
get serviceName() {
return NetworkService.SERVICE_NAME;
}
/**
* Times the execution of an asynchronous operation.
*
@@ -12,6 +12,10 @@ class NotificationService {
this.notificationUtils = notificationUtils;
}
get serviceName() {
return NotificationService.SERVICE_NAME;
}
sendNotification = async ({ notification, subject, content, html }) => {
const { type, address } = notification;
@@ -1,9 +1,17 @@
const SERVICE_NAME = "NotificationUtils";
class NotificationUtils {
static SERVICE_NAME = SERVICE_NAME;
constructor({ stringService, emailService }) {
this.stringService = stringService;
this.emailService = emailService;
}
get serviceName() {
return NotificationUtils.SERVICE_NAME;
}
buildTestEmail = async () => {
const context = { testName: "Monitoring System" };
const html = await this.emailService.buildEmail("testEmailTemplate", context);
@@ -4,6 +4,7 @@ const SERVICE_NAME = "StatusService";
class StatusService {
static SERVICE_NAME = SERVICE_NAME;
/**
* Creates an instance of StatusService.
*
@@ -14,7 +15,10 @@ class StatusService {
this.db = db;
this.logger = logger;
this.buffer = buffer;
this.SERVICE_NAME = SERVICE_NAME;
}
get serviceName() {
return StatusService.SERVICE_NAME;
}
async updateRunningStats({ monitor, networkResponse }) {