notificationsService
This commit is contained in:
1 parent
391f42ee53
commit
4e9839e2e5
6 files changed
+46
-52
No files matched your search
@@ -8,6 +8,7 @@ import BufferService from "../service/infrastructure/bufferService.js";
|
|||||||
import StatusService from "../service/infrastructure/statusService.js";
|
import StatusService from "../service/infrastructure/statusService.js";
|
||||||
import NotificationUtils from "../service/infrastructure/notificationUtils.js";
|
import NotificationUtils from "../service/infrastructure/notificationUtils.js";
|
||||||
import NotificationService from "../service/infrastructure/notificationService.js";
|
import NotificationService from "../service/infrastructure/notificationService.js";
|
||||||
|
import { NotificationsService } from "@/service/index.js";
|
||||||
import ErrorService from "../service/infrastructure/errorService.js";
|
import ErrorService from "../service/infrastructure/errorService.js";
|
||||||
import SuperSimpleQueueHelper from "../service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.js";
|
import SuperSimpleQueueHelper from "../service/infrastructure/SuperSimpleQueue/SuperSimpleQueueHelper.js";
|
||||||
import SuperSimpleQueue from "../service/infrastructure/SuperSimpleQueue/SuperSimpleQueue.js";
|
import SuperSimpleQueue from "../service/infrastructure/SuperSimpleQueue/SuperSimpleQueue.js";
|
||||||
@@ -206,9 +207,9 @@ export const initializeServices = async ({
|
|||||||
checksRepository,
|
checksRepository,
|
||||||
});
|
});
|
||||||
|
|
||||||
const bufferService = new BufferService({ db, logger, envSettings, incidentService, checkService });
|
const bufferService = new BufferService({ logger, incidentService, checkService });
|
||||||
|
|
||||||
const statusService = new StatusService({ db, logger, buffer: bufferService, incidentService, monitorsRepository });
|
const statusService = new StatusService({ db, logger, buffer: bufferService, monitorsRepository });
|
||||||
|
|
||||||
const notificationUtils = new NotificationUtils({
|
const notificationUtils = new NotificationUtils({
|
||||||
stringService,
|
stringService,
|
||||||
@@ -225,12 +226,15 @@ export const initializeServices = async ({
|
|||||||
notificationUtils,
|
notificationUtils,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const notificationsService = new NotificationsService();
|
||||||
|
|
||||||
const superSimpleQueueHelper = new SuperSimpleQueueHelper({
|
const superSimpleQueueHelper = new SuperSimpleQueueHelper({
|
||||||
db,
|
db,
|
||||||
logger,
|
logger,
|
||||||
networkService,
|
networkService,
|
||||||
statusService,
|
statusService,
|
||||||
notificationService,
|
notificationService,
|
||||||
|
notificationsService,
|
||||||
checkService,
|
checkService,
|
||||||
buffer: bufferService,
|
buffer: bufferService,
|
||||||
});
|
});
|
||||||
@@ -317,6 +321,7 @@ export const initializeServices = async ({
|
|||||||
invitesRepository,
|
invitesRepository,
|
||||||
recoveryTokensRepository,
|
recoveryTokensRepository,
|
||||||
settingsRepository,
|
settingsRepository,
|
||||||
|
notificationsService,
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.values(services).forEach((service) => {
|
Object.values(services).forEach((service) => {
|
||||||
|
|||||||
@@ -2,3 +2,4 @@ export * from "@/service/business/monitorService.js";
|
|||||||
export * from "@/service/infrastructure/networkService.js";
|
export * from "@/service/infrastructure/networkService.js";
|
||||||
export * from "@/service/infrastructure/notificationProviders/webhook.js";
|
export * from "@/service/infrastructure/notificationProviders/webhook.js";
|
||||||
export * from "@/service/infrastructure/notificationProviders/INotificationProvider.js";
|
export * from "@/service/infrastructure/notificationProviders/INotificationProvider.js";
|
||||||
|
export * from "@/service/infrastructure/notificationsService.js";
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
const SERVICE_NAME = "JobQueueHelper";
|
const SERVICE_NAME = "JobQueueHelper";
|
||||||
import type { Monitor } from "@/types/monitor.js";
|
import type { Monitor } from "@/types/monitor.js";
|
||||||
import { AppError } from "@/utils/AppError.js";
|
import { AppError } from "@/utils/AppError.js";
|
||||||
import { INetworkService } from "@/service/index.js";
|
import { INetworkService, INotificationsService } from "@/service/index.js";
|
||||||
class SuperSimpleQueueHelper {
|
class SuperSimpleQueueHelper {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
|
|
||||||
@@ -10,6 +10,7 @@ class SuperSimpleQueueHelper {
|
|||||||
private networkService: INetworkService;
|
private networkService: INetworkService;
|
||||||
private statusService: any;
|
private statusService: any;
|
||||||
private notificationService: any;
|
private notificationService: any;
|
||||||
|
private notificationsService: INotificationsService;
|
||||||
private checkService: any;
|
private checkService: any;
|
||||||
private buffer: any;
|
private buffer: any;
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ class SuperSimpleQueueHelper {
|
|||||||
networkService,
|
networkService,
|
||||||
statusService,
|
statusService,
|
||||||
notificationService,
|
notificationService,
|
||||||
|
notificationsService,
|
||||||
checkService,
|
checkService,
|
||||||
buffer,
|
buffer,
|
||||||
}: {
|
}: {
|
||||||
@@ -27,6 +29,7 @@ class SuperSimpleQueueHelper {
|
|||||||
networkService: INetworkService;
|
networkService: INetworkService;
|
||||||
statusService: any;
|
statusService: any;
|
||||||
notificationService: any;
|
notificationService: any;
|
||||||
|
notificationsService: INotificationsService;
|
||||||
checkService: any;
|
checkService: any;
|
||||||
buffer: any;
|
buffer: any;
|
||||||
}) {
|
}) {
|
||||||
@@ -37,6 +40,7 @@ class SuperSimpleQueueHelper {
|
|||||||
this.notificationService = notificationService;
|
this.notificationService = notificationService;
|
||||||
this.checkService = checkService;
|
this.checkService = checkService;
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
|
this.notificationsService = notificationsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
get serviceName() {
|
get serviceName() {
|
||||||
@@ -78,22 +82,27 @@ class SuperSimpleQueueHelper {
|
|||||||
// Step 4. Update monitor status
|
// Step 4. Update monitor status
|
||||||
const statusChangeResult = await this.statusService.updateMonitorStatus(status, check);
|
const statusChangeResult = await this.statusService.updateMonitorStatus(status, check);
|
||||||
|
|
||||||
this.notificationService
|
// Step 5 handle incidents and notifications
|
||||||
.handleNotifications({
|
if (statusChangeResult.statusChanged === true) {
|
||||||
...status,
|
this.notificationsService.handleNotifications(monitor, status);
|
||||||
monitor: statusChangeResult.monitor,
|
}
|
||||||
prevStatus: statusChangeResult.prevStatus,
|
|
||||||
statusChanged: statusChangeResult.statusChanged,
|
// this.notificationService
|
||||||
})
|
// .handleNotifications({
|
||||||
.catch((error: any) => {
|
// ...status,
|
||||||
this.logger.error({
|
// monitor: statusChangeResult.monitor,
|
||||||
message: error.message,
|
// prevStatus: statusChangeResult.prevStatus,
|
||||||
service: SERVICE_NAME,
|
// statusChanged: statusChangeResult.statusChanged,
|
||||||
method: "getMonitorJob",
|
// })
|
||||||
details: `Error sending notifications for job ${monitor.id}: ${error.message}`,
|
// .catch((error: any) => {
|
||||||
stack: error.stack,
|
// this.logger.error({
|
||||||
});
|
// message: error.message,
|
||||||
});
|
// service: SERVICE_NAME,
|
||||||
|
// method: "getMonitorJob",
|
||||||
|
// details: `Error sending notifications for job ${monitor.id}: ${error.message}`,
|
||||||
|
// stack: error.stack,
|
||||||
|
// });
|
||||||
|
// });
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
this.logger.warn({
|
this.logger.warn({
|
||||||
message: error.message,
|
message: error.message,
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ const SERVICE_NAME = "BufferService";
|
|||||||
class BufferService {
|
class BufferService {
|
||||||
static SERVICE_NAME = SERVICE_NAME;
|
static SERVICE_NAME = SERVICE_NAME;
|
||||||
private BUFFER_TIMEOUT: number;
|
private BUFFER_TIMEOUT: number;
|
||||||
private db: any;
|
|
||||||
private logger: any;
|
private logger: any;
|
||||||
private incidentService: any;
|
private incidentService: any;
|
||||||
private SERVICE_NAME: string;
|
private SERVICE_NAME: string;
|
||||||
@@ -15,21 +14,8 @@ class BufferService {
|
|||||||
private bufferTimer: NodeJS.Timeout | null = null;
|
private bufferTimer: NodeJS.Timeout | null = null;
|
||||||
private checksService: any;
|
private checksService: any;
|
||||||
|
|
||||||
constructor({
|
constructor({ logger, incidentService, checkService }: { logger: any; incidentService: any; checkService: any }) {
|
||||||
db,
|
|
||||||
logger,
|
|
||||||
envSettings,
|
|
||||||
incidentService,
|
|
||||||
checkService,
|
|
||||||
}: {
|
|
||||||
db: any;
|
|
||||||
logger: any;
|
|
||||||
envSettings: any;
|
|
||||||
incidentService: any;
|
|
||||||
checkService: any;
|
|
||||||
}) {
|
|
||||||
this.BUFFER_TIMEOUT = config.NODE_ENV === "development" ? 10 : 1000 * 60 * 1; // 1 minute
|
this.BUFFER_TIMEOUT = config.NODE_ENV === "development" ? 10 : 1000 * 60 * 1; // 1 minute
|
||||||
this.db = db;
|
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.incidentService = incidentService;
|
this.incidentService = incidentService;
|
||||||
this.checksService = checkService;
|
this.checksService = checkService;
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
import type { Monitor } from "@/types/index.js";
|
import type { Monitor, MonitorStatusResponse } from "@/types/index.js";
|
||||||
interface INotificationSerivce {
|
export interface INotificationsService {
|
||||||
handleNotifications: (moniotr: Monitor) => Promise<void>;
|
handleNotifications: (monitor: Monitor, monitorStatusResponse: MonitorStatusResponse) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class NotificationsService implements INotificationsService {
|
||||||
|
handleNotifications = async (monitor: Monitor, monitorStatusResponse: MonitorStatusResponse) => {
|
||||||
|
console.log(JSON.stringify(monitor, null, 2));
|
||||||
|
console.log(JSON.stringify(monitorStatusResponse, null, 2));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -17,26 +17,12 @@ class StatusService {
|
|||||||
private db: any;
|
private db: any;
|
||||||
private logger: any;
|
private logger: any;
|
||||||
private buffer: any;
|
private buffer: any;
|
||||||
private incidentService: any;
|
|
||||||
private monitorsRepository: IMonitorsRepository;
|
private monitorsRepository: IMonitorsRepository;
|
||||||
|
|
||||||
constructor({
|
constructor({ db, logger, buffer, monitorsRepository }: { db: any; logger: any; buffer: any; monitorsRepository: IMonitorsRepository }) {
|
||||||
db,
|
|
||||||
logger,
|
|
||||||
buffer,
|
|
||||||
incidentService,
|
|
||||||
monitorsRepository,
|
|
||||||
}: {
|
|
||||||
db: any;
|
|
||||||
logger: any;
|
|
||||||
buffer: any;
|
|
||||||
incidentService: any;
|
|
||||||
monitorsRepository: IMonitorsRepository;
|
|
||||||
}) {
|
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.buffer = buffer;
|
this.buffer = buffer;
|
||||||
this.incidentService = incidentService;
|
|
||||||
this.monitorsRepository = monitorsRepository;
|
this.monitorsRepository = monitorsRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user