cleanup imports

This commit is contained in:
Alex Holliday committed 2026-02-24 19:36:45 +00:00
1 parent 432d1d8ccf
commit 89a7fdbe34
4 files changed
+53 -65

No files matched your search

+5 -9
View File
@@ -181,13 +181,13 @@ export const initializeServices = async ({
notificationMessageBuilder notificationMessageBuilder
); );
const superSimpleQueueHelper = new SuperSimpleQueueHelper({ const superSimpleQueueHelper = new SuperSimpleQueueHelper(
logger, logger,
networkService, networkService,
statusService, statusService,
notificationsService, notificationsService,
checkService, checkService,
buffer: bufferService, bufferService,
incidentService, incidentService,
maintenanceWindowsRepository, maintenanceWindowsRepository,
monitorsRepository, monitorsRepository,
@@ -195,14 +195,10 @@ export const initializeServices = async ({
monitorStatsRepository, monitorStatsRepository,
checksRepository, checksRepository,
incidentsRepository, incidentsRepository,
geoChecksService, geoChecksService
}); );
const superSimpleQueue = await SuperSimpleQueue.create({ const superSimpleQueue = await SuperSimpleQueue.create(logger, superSimpleQueueHelper, monitorsRepository);
logger,
helper: superSimpleQueueHelper,
monitorsRepository,
});
// Business services // Business services
const userService = new UserService({ const userService = new UserService({
@@ -1,5 +1,7 @@
import { IMonitorsRepository } from "@/repositories/index.js"; import { IMonitorsRepository } from "@/repositories/index.js";
import { ILogger } from "@/utils/logger.js";
import Scheduler from "super-simple-scheduler"; import Scheduler from "super-simple-scheduler";
import { ISuperSimpleQueueHelper } from "@/service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.js";
const SERVICE_NAME = "JobQueue"; const SERVICE_NAME = "JobQueue";
type QueueJobFailure = { type QueueJobFailure = {
@@ -54,22 +56,12 @@ export interface ISuperSimpleQueue {
class SuperSimpleQueue implements ISuperSimpleQueue { class SuperSimpleQueue implements ISuperSimpleQueue {
static SERVICE_NAME = SERVICE_NAME; static SERVICE_NAME = SERVICE_NAME;
private logger: any; private logger: ILogger;
private helper: any; private helper: ISuperSimpleQueueHelper;
private monitorsRepository: IMonitorsRepository; private monitorsRepository: IMonitorsRepository;
private readonly scheduler: Scheduler; private readonly scheduler: Scheduler;
constructor({ constructor(logger: ILogger, helper: ISuperSimpleQueueHelper, monitorsRepository: IMonitorsRepository, scheduler: Scheduler) {
logger,
helper,
monitorsRepository,
scheduler,
}: {
logger: any;
helper: any;
monitorsRepository: IMonitorsRepository;
scheduler: Scheduler;
}) {
this.logger = logger; this.logger = logger;
this.helper = helper; this.helper = helper;
this.monitorsRepository = monitorsRepository; this.monitorsRepository = monitorsRepository;
@@ -80,14 +72,14 @@ class SuperSimpleQueue implements ISuperSimpleQueue {
return SuperSimpleQueue.SERVICE_NAME; return SuperSimpleQueue.SERVICE_NAME;
} }
static async create({ logger, helper, monitorsRepository }: { logger: any; helper: any; monitorsRepository: IMonitorsRepository }) { static async create(logger: ILogger, helper: ISuperSimpleQueueHelper, monitorsRepository: IMonitorsRepository) {
const scheduler = new Scheduler({ const scheduler = new Scheduler({
// storeType: "mongo", // storeType: "mongo",
// storeType: "redis", // storeType: "redis",
logLevel: "debug", logLevel: "debug",
// dbUri: envSettings.dbConnectionString, // dbUri: envSettings.dbConnectionString,
}); });
const instance = new SuperSimpleQueue({ logger, helper, monitorsRepository, scheduler }); const instance = new SuperSimpleQueue(logger, helper, monitorsRepository, scheduler);
await instance.init(); await instance.init();
return instance; return instance;
} }
@@ -113,7 +105,7 @@ class SuperSimpleQueue implements ISuperSimpleQueue {
this.scheduler.addJob({ id: "cleanup-orphaned", template: "cleanup-orphaned", active: true }); this.scheduler.addJob({ id: "cleanup-orphaned", template: "cleanup-orphaned", active: true });
return true; return true;
} catch (error) { } catch (error: any) {
this.logger.error({ this.logger.error({
message: "Failed to initialize SuperSimpleQueue", message: "Failed to initialize SuperSimpleQueue",
service: SERVICE_NAME, service: SERVICE_NAME,
@@ -13,6 +13,16 @@ import {
IChecksRepository, IChecksRepository,
IIncidentsRepository, IIncidentsRepository,
} from "@/repositories/index.js"; } from "@/repositories/index.js";
import { ILogger } from "@/utils/logger.js";
import { IBufferService } from "../bufferService.js";
export interface ISuperSimpleQueueHelper {
readonly serviceName: string;
getMonitorJob(): (monitor: Monitor) => Promise<void>;
getCleanupOrphanedJob(): () => Promise<void>;
getGeoCheckJob(): (monitor: Monitor) => Promise<void>;
isInMaintenanceWindow(monitorId: string, teamId: string): Promise<boolean>;
}
export interface MonitorActionDecision { export interface MonitorActionDecision {
shouldCreateIncident: boolean; shouldCreateIncident: boolean;
@@ -28,7 +38,7 @@ export interface MonitorActionDecision {
}; };
} }
class SuperSimpleQueueHelper { class SuperSimpleQueueHelper implements ISuperSimpleQueueHelper {
static SERVICE_NAME = SERVICE_NAME; static SERVICE_NAME = SERVICE_NAME;
private logger: any; private logger: any;
@@ -36,7 +46,7 @@ class SuperSimpleQueueHelper {
private statusService: IStatusService; private statusService: IStatusService;
private notificationsService: INotificationsService; private notificationsService: INotificationsService;
private checkService: any; private checkService: any;
private buffer: any; private buffer: IBufferService;
private incidentService: IncidentService; private incidentService: IncidentService;
private maintenanceWindowsRepository: IMaintenanceWindowsRepository; private maintenanceWindowsRepository: IMaintenanceWindowsRepository;
private monitorsRepository: IMonitorsRepository; private monitorsRepository: IMonitorsRepository;
@@ -46,37 +56,22 @@ class SuperSimpleQueueHelper {
private incidentsRepository: IIncidentsRepository; private incidentsRepository: IIncidentsRepository;
private geoChecksService: IGeoChecksService; private geoChecksService: IGeoChecksService;
constructor({ constructor(
logger, logger: ILogger,
networkService, networkService: INetworkService,
statusService, statusService: IStatusService,
notificationsService, notificationsService: INotificationsService,
checkService, checkService: any,
buffer, buffer: IBufferService,
incidentService, incidentService: IncidentService,
maintenanceWindowsRepository, maintenanceWindowsRepository: IMaintenanceWindowsRepository,
monitorsRepository, monitorsRepository: IMonitorsRepository,
teamsRepository, teamsRepository: ITeamsRepository,
monitorStatsRepository, monitorStatsRepository: IMonitorStatsRepository,
checksRepository, checksRepository: IChecksRepository,
incidentsRepository, incidentsRepository: IIncidentsRepository,
geoChecksService, geoChecksService: IGeoChecksService
}: { ) {
logger: any;
networkService: INetworkService;
statusService: IStatusService;
notificationsService: INotificationsService;
checkService: any;
buffer: any;
incidentService: IncidentService;
maintenanceWindowsRepository: IMaintenanceWindowsRepository;
monitorsRepository: IMonitorsRepository;
teamsRepository: ITeamsRepository;
monitorStatsRepository: IMonitorStatsRepository;
checksRepository: IChecksRepository;
incidentsRepository: IIncidentsRepository;
geoChecksService: IGeoChecksService;
}) {
this.logger = logger; this.logger = logger;
this.networkService = networkService; this.networkService = networkService;
this.statusService = statusService; this.statusService = statusService;
@@ -1,6 +1,8 @@
import { HTTPError, RequestError } from "got"; import { HTTPError, RequestError } from "got";
import type { Got, Response } from "got"; import type { Got, Response } from "got";
import type { Monitor, MonitorStatusResponse } from "@/types/index.js"; import type { Monitor, MonitorStatusResponse } from "@/types/index.js";
import type { AxiosStatic } from "axios";
import type Docker from "dockerode";
import CacheableLookup from "cacheable-lookup"; import CacheableLookup from "cacheable-lookup";
import { ISettingsService } from "../system/settingsService.js"; import { ISettingsService } from "../system/settingsService.js";
@@ -48,16 +50,16 @@ class NetworkService implements INetworkService {
private NETWORK_ERROR: number; private NETWORK_ERROR: number;
private PING_ERROR: number; private PING_ERROR: number;
private axios: any; private axios: AxiosStatic;
private got: Got; private got: Got;
private https: any; private https: any;
private jmespath: any; private jmespath: any;
private GameDig: any; private GameDig: any;
private ping: any; private ping: any;
private logger: any; private logger: ILogger;
private Docker: any; private Docker: any;
private net: any; private net: any;
private settingsService: any; private settingsService: ISettingsService;
private buildStatusResponse = <T>({ private buildStatusResponse = <T>({
monitor, monitor,
@@ -114,7 +116,7 @@ class NetworkService implements INetworkService {
}; };
constructor( constructor(
axios: any, axios: AxiosStatic,
got: Got, got: Got,
https: any, https: any,
jmespath: any, jmespath: any,
@@ -423,7 +425,6 @@ class NetworkService implements INetworkService {
const docker = new this.Docker({ const docker = new this.Docker({
socketPath: "/var/run/docker.sock", socketPath: "/var/run/docker.sock",
handleError: true, // Enable error handling
}); });
const dockerResponse = this.buildStatusResponse({ const dockerResponse = this.buildStatusResponse({
@@ -519,6 +520,10 @@ class NetworkService implements INetworkService {
private async requestPort(monitor: Monitor): Promise<MonitorStatusResponse> { private async requestPort(monitor: Monitor): Promise<MonitorStatusResponse> {
try { try {
const { url, port } = monitor; const { url, port } = monitor;
if (!port) {
throw new Error("Port is required for port monitor");
}
const { response, responseTime, error } = await this.timeRequest(async () => { const { response, responseTime, error } = await this.timeRequest(async () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const socket = this.net.createConnection( const socket = this.net.createConnection(
@@ -585,9 +590,9 @@ class NetworkService implements INetworkService {
}); });
const state = await this.GameDig.query({ const state = await this.GameDig.query({
type: gameId, type: gameId ?? "unknown",
host: url, host: url,
port: port, port: port ?? 0,
}).catch((error: any) => { }).catch((error: any) => {
this.logger.warn({ this.logger.warn({
message: error.message, message: error.message,