standardize log statements
This commit is contained in:
1 parent
6984eb8a70
commit
a0248c81c2
12 files changed
+167
-115
No files matched your search
@@ -79,10 +79,10 @@ const registerUser = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newUser = await req.db.insertUser({ ...req.body }, req.file);
|
const newUser = await req.db.insertUser({ ...req.body }, req.file);
|
||||||
|
logger.info({
|
||||||
logger.info(successMessages.AUTH_CREATE_USER, {
|
message: successMessages.AUTH_CREATE_USER,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
userId: newUser._id,
|
details: newUser._id,
|
||||||
});
|
});
|
||||||
|
|
||||||
const userForToken = { ...newUser._doc };
|
const userForToken = { ...newUser._doc };
|
||||||
@@ -102,9 +102,11 @@ const registerUser = async (req, res, next) => {
|
|||||||
"Welcome to Uptime Monitor"
|
"Welcome to Uptime Monitor"
|
||||||
)
|
)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
logger.error("Error sending welcome email", {
|
logger.error({
|
||||||
|
message: error.message,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
error: error.message,
|
method: "registerUser",
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -53,9 +53,11 @@ const issueInvitation = async (req, res, next) => {
|
|||||||
"Welcome to Uptime Monitor"
|
"Welcome to Uptime Monitor"
|
||||||
)
|
)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
logger.error("Error sending invite email", {
|
logger.error({
|
||||||
|
message: error.message,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
error: error.message,
|
method: "issueInvitation",
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {
|
|||||||
getMonitorByIdQueryValidation,
|
getMonitorByIdQueryValidation,
|
||||||
getMonitorsByTeamIdValidation,
|
getMonitorsByTeamIdValidation,
|
||||||
createMonitorBodyValidation,
|
createMonitorBodyValidation,
|
||||||
getMonitorURLByQueryValidation,
|
getMonitorURLByQueryValidation,
|
||||||
editMonitorBodyValidation,
|
editMonitorBodyValidation,
|
||||||
getMonitorsAndSummaryByTeamIdParamValidation,
|
getMonitorsAndSummaryByTeamIdParamValidation,
|
||||||
getMonitorsAndSummaryByTeamIdQueryValidation,
|
getMonitorsAndSummaryByTeamIdQueryValidation,
|
||||||
@@ -270,32 +270,32 @@ const createMonitor = async (req, res, next) => {
|
|||||||
* @throws {Error} If there is an error during the process, especially if there is a validation error (422).
|
* @throws {Error} If there is an error during the process, especially if there is a validation error (422).
|
||||||
*/
|
*/
|
||||||
const checkEndpointResolution = async (req, res, next) => {
|
const checkEndpointResolution = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
await getMonitorURLByQueryValidation.validateAsync(req.query);
|
await getMonitorURLByQueryValidation.validateAsync(req.query);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(handleValidationError(error, SERVICE_NAME));
|
next(handleValidationError(error, SERVICE_NAME));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let { monitorURL } = req.query;
|
let { monitorURL } = req.query;
|
||||||
monitorURL = new URL(monitorURL);
|
monitorURL = new URL(monitorURL);
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
dns.resolve(monitorURL.hostname, (error) => {
|
dns.resolve(monitorURL.hostname, (error) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
}
|
}
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
msg: `URL resolved successfully`,
|
msg: `URL resolved successfully`,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(handleError(error, SERVICE_NAME, "checkEndpointResolution"));
|
next(handleError(error, SERVICE_NAME, "checkEndpointResolution"));
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a monitor by its ID and also deletes associated checks, alerts, and notifications.
|
* Deletes a monitor by its ID and also deletes associated checks, alerts, and notifications.
|
||||||
@@ -325,14 +325,12 @@ const deleteMonitor = async (req, res, next) => {
|
|||||||
await req.db.deletePageSpeedChecksByMonitorId(monitor._id);
|
await req.db.deletePageSpeedChecksByMonitorId(monitor._id);
|
||||||
await req.db.deleteNotificationsByMonitorId(monitor._id);
|
await req.db.deleteNotificationsByMonitorId(monitor._id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error({
|
||||||
`Error deleting associated records for monitor ${monitor._id} with name ${monitor.name}`,
|
message: `Error deleting associated records for monitor ${monitor._id} with name ${monitor.name}`,
|
||||||
{
|
service: SERVICE_NAME,
|
||||||
method: "deleteMonitor",
|
method: "deleteMonitor",
|
||||||
service: SERVICE_NAME,
|
stack: error.stack,
|
||||||
error: error.message,
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return res.status(200).json({ success: true, msg: successMessages.MONITOR_DELETE });
|
return res.status(200).json({ success: true, msg: successMessages.MONITOR_DELETE });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -365,12 +363,12 @@ const deleteAllMonitors = async (req, res, next) => {
|
|||||||
await req.db.deletePageSpeedChecksByMonitorId(monitor._id);
|
await req.db.deletePageSpeedChecksByMonitorId(monitor._id);
|
||||||
await req.db.deleteNotificationsByMonitorId(monitor._id);
|
await req.db.deleteNotificationsByMonitorId(monitor._id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error({
|
||||||
`Error deleting associated records for monitor ${monitor._id} with name ${monitor.name}`,
|
message: `Error deleting associated records for monitor ${monitor._id} with name ${monitor.name}`,
|
||||||
{
|
service: SERVICE_NAME,
|
||||||
method: "deleteAllMonitors",
|
method: "deleteAllMonitors",
|
||||||
}
|
stack: error.stack,
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -517,7 +515,7 @@ export {
|
|||||||
getMonitorsAndSummaryByTeamId,
|
getMonitorsAndSummaryByTeamId,
|
||||||
getMonitorsByTeamId,
|
getMonitorsByTeamId,
|
||||||
createMonitor,
|
createMonitor,
|
||||||
checkEndpointResolution,
|
checkEndpointResolution,
|
||||||
deleteMonitor,
|
deleteMonitor,
|
||||||
deleteAllMonitors,
|
deleteAllMonitors,
|
||||||
editMonitor,
|
editMonitor,
|
||||||
|
|||||||
@@ -19,11 +19,13 @@ const connect = async () => {
|
|||||||
appSettings = new AppSettings({});
|
appSettings = new AppSettings({});
|
||||||
await appSettings.save();
|
await appSettings.save();
|
||||||
}
|
}
|
||||||
logger.info("Connected to MongoDB", { service: SERVICE_NAME, method: "connect" });
|
logger.info({ message: "Connected to MongoDB" });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("failed to connect to MongoDB", {
|
logger.error({
|
||||||
|
message: error.message,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "connect",
|
method: "connect",
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@@ -31,14 +33,16 @@ const connect = async () => {
|
|||||||
|
|
||||||
const disconnect = async () => {
|
const disconnect = async () => {
|
||||||
try {
|
try {
|
||||||
logger.info("Disconnecting from MongoDB", { service: SERVICE_NAME });
|
logger.info({ message: "Disconnecting from MongoDB" });
|
||||||
await mongoose.disconnect();
|
await mongoose.disconnect();
|
||||||
logger.info("Disconnected from MongoDB", { service: SERVICE_NAME });
|
logger.info({ message: "Disconnected from MongoDB" });
|
||||||
return;
|
return;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("failed to disconnect from MongoDB", {
|
logger.error({
|
||||||
|
message: error.message,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
errorMsg: error.message,
|
method: "disconnect",
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -30,9 +30,11 @@ const createCheck = async (checkData) => {
|
|||||||
const monitor = await Monitor.findById(monitorId);
|
const monitor = await Monitor.findById(monitorId);
|
||||||
|
|
||||||
if (!monitor) {
|
if (!monitor) {
|
||||||
logger.error("Monitor not found", {
|
logger.error({
|
||||||
|
message: "Monitor not found",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
monitorId,
|
method: "createCheck",
|
||||||
|
details: `monitor ID: ${monitorId}`,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -248,9 +250,11 @@ const updateChecksTTL = async (teamId, ttl) => {
|
|||||||
try {
|
try {
|
||||||
await Check.collection.dropIndex("expiry_1");
|
await Check.collection.dropIndex("expiry_1");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Failed to drop index", {
|
logger.error({
|
||||||
|
message: error.message,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "updateChecksTTL",
|
method: "updateChecksTTL",
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-9
@@ -89,10 +89,15 @@ const startApp = async () => {
|
|||||||
//health check
|
//health check
|
||||||
app.use("/api/v1/healthy", (req, res) => {
|
app.use("/api/v1/healthy", (req, res) => {
|
||||||
try {
|
try {
|
||||||
logger.info("Checking Health of the server.");
|
logger.info({ message: "Checking Health of the server." });
|
||||||
return res.status(200).json({ message: "Healthy" });
|
return res.status(200).json({ message: "Healthy" });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error.message);
|
logger.error({
|
||||||
|
message: error.message,
|
||||||
|
service: SERVICE_NAME,
|
||||||
|
method: "healthCheck",
|
||||||
|
stack: error.stack,
|
||||||
|
});
|
||||||
return res.status(500).json({ message: error.message });
|
return res.status(500).json({ message: error.message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -106,7 +111,7 @@ const startApp = async () => {
|
|||||||
// Create services
|
// Create services
|
||||||
await db.connect();
|
await db.connect();
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`server started on port:${PORT}`);
|
logger.info({ message: `server started on port:${PORT}` });
|
||||||
});
|
});
|
||||||
const settingsService = new SettingsService(AppSettings);
|
const settingsService = new SettingsService(AppSettings);
|
||||||
|
|
||||||
@@ -132,19 +137,21 @@ const startApp = async () => {
|
|||||||
|
|
||||||
const cleanup = async () => {
|
const cleanup = async () => {
|
||||||
if (cleaningUp) {
|
if (cleaningUp) {
|
||||||
console.log("Already cleaning up");
|
logger.warn({ message: "Already cleaning up" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cleaningUp = true;
|
cleaningUp = true;
|
||||||
try {
|
try {
|
||||||
console.log("Shutting down gracefully");
|
logger.info({ message: "shutting down gracefully" });
|
||||||
await jobQueue.obliterate();
|
await jobQueue.obliterate();
|
||||||
await db.disconnect();
|
await db.disconnect();
|
||||||
console.log("Finished cleanup");
|
logger.info({ message: "shut down gracefully" });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(errorMessages.JOB_QUEUE_DELETE_JOB, {
|
logger.error({
|
||||||
|
message: error.message,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
errorMsg: error.message,
|
method: "cleanup",
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
@@ -155,8 +162,11 @@ const startApp = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
startApp().catch((error) => {
|
startApp().catch((error) => {
|
||||||
logger.error(error.message, {
|
logger.error({
|
||||||
|
message: error.message,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
|
method: "startApp",
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
@@ -5,9 +5,11 @@ const handleErrors = (error, req, res, next) => {
|
|||||||
const status = error.status || 500;
|
const status = error.status || 500;
|
||||||
const message = error.message || errorMessages.FRIENDLY_ERROR;
|
const message = error.message || errorMessages.FRIENDLY_ERROR;
|
||||||
const service = error.service || errorMessages.UNKNOWN_SERVICE;
|
const service = error.service || errorMessages.UNKNOWN_SERVICE;
|
||||||
logger.error(error.message, {
|
logger.error({
|
||||||
|
message: message,
|
||||||
service: service,
|
service: service,
|
||||||
method: error.method,
|
method: error.method,
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
res.status(status).json({ success: false, msg: message });
|
res.status(status).json({ success: false, msg: message });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ const verifyOwnership = (Model, paramName) => {
|
|||||||
const doc = await Model.findById(documentId);
|
const doc = await Model.findById(documentId);
|
||||||
//If the document is not found, return a 404 error
|
//If the document is not found, return a 404 error
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
logger.error(errorMessages.VERIFY_OWNER_NOT_FOUND, {
|
logger.error({
|
||||||
|
message: errorMessages.VERIFY_OWNER_NOT_FOUND,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
|
method: "verifyOwnership",
|
||||||
});
|
});
|
||||||
const error = new Error(errorMessages.VERIFY_OWNER_NOT_FOUND);
|
const error = new Error(errorMessages.VERIFY_OWNER_NOT_FOUND);
|
||||||
error.status = 404;
|
error.status = 404;
|
||||||
|
|||||||
@@ -37,8 +37,12 @@ const verifySuperAdmin = (req, res, next) => {
|
|||||||
|
|
||||||
jwt.verify(parsedToken, jwtSecret, (err, decoded) => {
|
jwt.verify(parsedToken, jwtSecret, (err, decoded) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.error(errorMessages.INVALID_AUTH_TOKEN, {
|
logger.error({
|
||||||
|
message: err.message,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
|
method: "verifySuperAdmin",
|
||||||
|
stack: err.stack,
|
||||||
|
details: errorMessages.INVALID_AUTH_TOKEN,
|
||||||
});
|
});
|
||||||
return res
|
return res
|
||||||
.status(401)
|
.status(401)
|
||||||
@@ -46,8 +50,11 @@ const verifySuperAdmin = (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (decoded.role.includes("superadmin") === false) {
|
if (decoded.role.includes("superadmin") === false) {
|
||||||
logger.error(errorMessages.INVALID_AUTH_TOKEN, {
|
logger.error({
|
||||||
|
message: errorMessages.INVALID_AUTH_TOKEN,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
|
method: "verifySuperAdmin",
|
||||||
|
stack: err.stack,
|
||||||
});
|
});
|
||||||
return res.status(401).json({ success: false, msg: errorMessages.UNAUTHORIZED });
|
return res.status(401).json({ success: false, msg: errorMessages.UNAUTHORIZED });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,9 +44,11 @@ class EmailService {
|
|||||||
const templateContent = this.fs.readFileSync(templatePath, "utf8");
|
const templateContent = this.fs.readFileSync(templatePath, "utf8");
|
||||||
return this.compile(templateContent);
|
return this.compile(templateContent);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error("Error loading Email templates", {
|
this.logger.error({
|
||||||
error,
|
message: error.message,
|
||||||
service: this.SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
|
method: "loadTemplate",
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -102,9 +104,11 @@ class EmailService {
|
|||||||
const html = await this.mjml2html(mjml);
|
const html = await this.mjml2html(mjml);
|
||||||
return html.html;
|
return html.html;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error("Error building Email HTML", {
|
this.logger.error({
|
||||||
error,
|
message: error.message,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
|
method: "buildAndSendEmail",
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -118,9 +122,11 @@ class EmailService {
|
|||||||
});
|
});
|
||||||
return info;
|
return info;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error("Error sending Email", {
|
this.logger.error({
|
||||||
error,
|
message: error.message,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
|
method: "sendEmail",
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
+34
-24
@@ -107,16 +107,19 @@ class JobQueue {
|
|||||||
if (!maintenanceWindowActive) {
|
if (!maintenanceWindowActive) {
|
||||||
await this.networkService.getStatus(job);
|
await this.networkService.getStatus(job);
|
||||||
} else {
|
} else {
|
||||||
this.logger.info(`Monitor ${monitorId} is in maintenance window`, {
|
this.logger.info({
|
||||||
|
message: `Monitor ${monitorId} is in maintenance window`,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
monitorId,
|
method: "createWorker",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`Error processing job ${job.id}: ${error.message}`, {
|
this.logger.error({
|
||||||
|
message: error.message,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
jobId: job.id,
|
method: "createWorker",
|
||||||
error: error,
|
details: `Error processing job ${job.id}: ${error.message}`,
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -197,14 +200,15 @@ class JobQueue {
|
|||||||
while (workersToRemove > 0 && this.workers.length > 5) {
|
while (workersToRemove > 0 && this.workers.length > 5) {
|
||||||
const worker = this.workers.pop();
|
const worker = this.workers.pop();
|
||||||
workersToRemove--;
|
workersToRemove--;
|
||||||
try {
|
await worker.close().catch((error) => {
|
||||||
await worker.close();
|
|
||||||
} catch (error) {
|
|
||||||
// Catch the error instead of throwing it
|
// Catch the error instead of throwing it
|
||||||
this.logger.error(errorMessages.JOB_QUEUE_WORKER_CLOSE, {
|
this.logger.error({
|
||||||
|
message: error.message,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
|
method: "scaleWorkers",
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -282,20 +286,24 @@ class JobQueue {
|
|||||||
*/
|
*/
|
||||||
async deleteJob(monitor) {
|
async deleteJob(monitor) {
|
||||||
try {
|
try {
|
||||||
const deleted = await this.queue.removeRepeatable(monitor._id, {
|
const wasDeleted = await this.queue.removeRepeatable(monitor._id, {
|
||||||
every: monitor.interval,
|
every: monitor.interval,
|
||||||
});
|
});
|
||||||
if (deleted) {
|
if (wasDeleted === true) {
|
||||||
this.logger.info(successMessages.JOB_QUEUE_DELETE_JOB, {
|
this.logger.info({
|
||||||
|
message: successMessages.JOB_QUEUE_DELETE_JOB,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
jobId: monitor.id,
|
method: "deleteJob",
|
||||||
|
details: `Deleted job ${monitor._id}`,
|
||||||
});
|
});
|
||||||
const workerStats = await this.getWorkerStats();
|
const workerStats = await this.getWorkerStats();
|
||||||
await this.scaleWorkers(workerStats);
|
await this.scaleWorkers(workerStats);
|
||||||
} else {
|
} else {
|
||||||
this.logger.error(errorMessages.JOB_QUEUE_DELETE_JOB, {
|
this.logger.error({
|
||||||
|
message: errorMessages.JOB_QUEUE_DELETE_JOB,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
jobId: monitor.id,
|
method: "deleteJob",
|
||||||
|
details: `Failed to delete job ${monitor._id}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -315,12 +323,16 @@ class JobQueue {
|
|||||||
delayed: await this.queue.getDelayedCount(),
|
delayed: await this.queue.getDelayedCount(),
|
||||||
repeatableJobs: (await this.queue.getRepeatableJobs()).length,
|
repeatableJobs: (await this.queue.getRepeatableJobs()).length,
|
||||||
};
|
};
|
||||||
console.log(metrics);
|
this.logger.info({
|
||||||
|
message: metrics,
|
||||||
|
});
|
||||||
return metrics;
|
return metrics;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error("Failed to retrieve job queue metrics", {
|
this.logger.error({
|
||||||
|
message: error.message,
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
errorMsg: error.message,
|
method: "getMetrics",
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -332,7 +344,7 @@ class JobQueue {
|
|||||||
async obliterate() {
|
async obliterate() {
|
||||||
try {
|
try {
|
||||||
let metrics = await this.getMetrics();
|
let metrics = await this.getMetrics();
|
||||||
console.log(metrics);
|
this.logger.info({ message: metrics });
|
||||||
await this.queue.pause();
|
await this.queue.pause();
|
||||||
const jobs = await this.getJobs();
|
const jobs = await this.getJobs();
|
||||||
|
|
||||||
@@ -348,10 +360,8 @@ class JobQueue {
|
|||||||
|
|
||||||
await this.queue.obliterate();
|
await this.queue.obliterate();
|
||||||
metrics = await this.getMetrics();
|
metrics = await this.getMetrics();
|
||||||
console.log(metrics);
|
this.logger.info({ message: metrics });
|
||||||
this.logger.info(successMessages.JOB_QUEUE_OBLITERATE, {
|
this.logger.info({ message: successMessages.JOB_QUEUE_OBLITERATE });
|
||||||
service: SERVICE_NAME,
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
error.service === undefined ? (error.service = SERVICE_NAME) : null;
|
||||||
|
|||||||
@@ -56,10 +56,12 @@ class NetworkService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error.message, {
|
this.logger.error({
|
||||||
method: "handleNotification",
|
message: error.message,
|
||||||
service: this.SERVICE_NAME,
|
service: this.SERVICE_NAME,
|
||||||
monitorId: monitor._id,
|
method: "handleNotification",
|
||||||
|
details: `notification error for monitor: ${monitor._id}`,
|
||||||
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,19 +81,18 @@ class NetworkService {
|
|||||||
try {
|
try {
|
||||||
monitor = await this.db.getMonitorById(_id);
|
monitor = await this.db.getMonitorById(_id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
this.logger.error({
|
||||||
|
message: error.message,
|
||||||
|
service: this.SERVICE_NAME,
|
||||||
|
method: "handleStatusUpdate",
|
||||||
|
stack: error.stack,
|
||||||
|
details: `monitor lookup error for monitor: ${_id}`,
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, try to update monitor status
|
// Otherwise, try to update monitor status
|
||||||
try {
|
try {
|
||||||
if (monitor === null || monitor === undefined) {
|
|
||||||
this.logger.error(`Null Monitor: ${_id}`, {
|
|
||||||
method: "handleStatusUpdate",
|
|
||||||
service: this.SERVICE_NAME,
|
|
||||||
jobId: job.id,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (monitor.status === undefined || monitor.status !== isAlive) {
|
if (monitor.status === undefined || monitor.status !== isAlive) {
|
||||||
const oldStatus = monitor.status;
|
const oldStatus = monitor.status;
|
||||||
monitor.status = isAlive;
|
monitor.status = isAlive;
|
||||||
@@ -102,10 +103,12 @@ class NetworkService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(error.message, {
|
this.logger.error({
|
||||||
method: "handleStatusUpdate",
|
message: error.message,
|
||||||
service: this.SERVICE_NAME,
|
service: this.SERVICE_NAME,
|
||||||
jobId: job.id,
|
method: "handleStatusUpdate",
|
||||||
|
stack: error.stack,
|
||||||
|
details: `status update error for monitor: ${_id}`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -391,11 +394,12 @@ class NetworkService {
|
|||||||
case this.TYPE_HARDWARE:
|
case this.TYPE_HARDWARE:
|
||||||
return await this.handleHardware(job);
|
return await this.handleHardware(job);
|
||||||
default:
|
default:
|
||||||
this.logger.error(`Unsupported type: ${job.data.type}`, {
|
this.logger.error({
|
||||||
|
message: `Unsupported type: ${job.data.type}`,
|
||||||
service: this.SERVICE_NAME,
|
service: this.SERVICE_NAME,
|
||||||
method: "getStatus",
|
method: "getStatus",
|
||||||
jobId: job.id,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -417,11 +421,12 @@ class NetworkService {
|
|||||||
}
|
}
|
||||||
throw new Error();
|
throw new Error();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(`Error writing check for ${data.monitorId}`, {
|
this.logger.error({
|
||||||
|
message: error.message,
|
||||||
service: this.SERVICE_NAME,
|
service: this.SERVICE_NAME,
|
||||||
method: "logAndStoreCheck",
|
method: "logAndStoreCheck",
|
||||||
monitorId: data.monitorId,
|
details: `Error writing check for ${data.monitorId}`,
|
||||||
error: error,
|
stack: error.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user