Merge remote-tracking branch 'upstream/develop' into fix/colorful-revamp-extravaganza
This commit is contained in:
commit
bd1d1d8082
5 files changed
+27
-11
No files matched your search
@@ -35,7 +35,7 @@ export const getPageSpeedByTeamId = createAsyncThunk(
|
|||||||
try {
|
try {
|
||||||
const res = await networkService.getMonitorsByTeamId(
|
const res = await networkService.getMonitorsByTeamId(
|
||||||
token,
|
token,
|
||||||
user._id,
|
user.teamId,
|
||||||
25,
|
25,
|
||||||
["pagespeed"],
|
["pagespeed"],
|
||||||
null,
|
null,
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ const CreatePageSpeed = () => {
|
|||||||
...monitor,
|
...monitor,
|
||||||
description: monitor.name,
|
description: monitor.name,
|
||||||
userId: user._id,
|
userId: user._id,
|
||||||
|
teamId: user.teamId,
|
||||||
interval: form.interval * MS_PER_MINUTE,
|
interval: form.interval * MS_PER_MINUTE,
|
||||||
type: "pagespeed",
|
type: "pagespeed",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -151,8 +151,7 @@ const loginController = async (req, res, next) => {
|
|||||||
|
|
||||||
// Happy path, return token
|
// Happy path, return token
|
||||||
const token = issueToken(userWithoutPassword);
|
const token = issueToken(userWithoutPassword);
|
||||||
user.authToken = token;
|
|
||||||
await user.save();
|
|
||||||
// reset avatar image
|
// reset avatar image
|
||||||
userWithoutPassword.avatarImage = user.avatarImage;
|
userWithoutPassword.avatarImage = user.avatarImage;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const ping = require("ping");
|
const ping = require("ping");
|
||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
|
const http = require("http");
|
||||||
|
const { errorMessages, successMessages } = require("../utils/messages");
|
||||||
|
|
||||||
class NetworkService {
|
class NetworkService {
|
||||||
constructor(db, emailService) {
|
constructor(db, emailService) {
|
||||||
@@ -84,11 +86,13 @@ class NetworkService {
|
|||||||
const { responseTime, response } =
|
const { responseTime, response } =
|
||||||
await this.measureResponseTime(operation);
|
await this.measureResponseTime(operation);
|
||||||
isAlive = response.alive;
|
isAlive = response.alive;
|
||||||
|
|
||||||
const checkData = {
|
const checkData = {
|
||||||
monitorId: job.data._id,
|
monitorId: job.data._id,
|
||||||
status: isAlive,
|
status: isAlive,
|
||||||
responseTime,
|
responseTime,
|
||||||
|
message: isAlive
|
||||||
|
? successMessages.PING_SUCCESS
|
||||||
|
: errorMessages.PING_CANNOT_RESOLVE,
|
||||||
};
|
};
|
||||||
return await this.logAndStoreCheck(checkData, this.db.createCheck);
|
return await this.logAndStoreCheck(checkData, this.db.createCheck);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -96,6 +100,7 @@ class NetworkService {
|
|||||||
const checkData = {
|
const checkData = {
|
||||||
monitorId: job.data._id,
|
monitorId: job.data._id,
|
||||||
status: isAlive,
|
status: isAlive,
|
||||||
|
message: errorMessages.PING_CANNOT_RESOLVE,
|
||||||
responseTime: error.responseTime,
|
responseTime: error.responseTime,
|
||||||
};
|
};
|
||||||
return await this.logAndStoreCheck(checkData, this.db.createCheck);
|
return await this.logAndStoreCheck(checkData, this.db.createCheck);
|
||||||
@@ -122,7 +127,6 @@ class NetworkService {
|
|||||||
try {
|
try {
|
||||||
const { responseTime, response } =
|
const { responseTime, response } =
|
||||||
await this.measureResponseTime(operation);
|
await this.measureResponseTime(operation);
|
||||||
|
|
||||||
// check if response is in the 200 range, if so, service is up
|
// check if response is in the 200 range, if so, service is up
|
||||||
isAlive = response.status >= 200 && response.status < 300;
|
isAlive = response.status >= 200 && response.status < 300;
|
||||||
|
|
||||||
@@ -132,21 +136,21 @@ class NetworkService {
|
|||||||
status: isAlive,
|
status: isAlive,
|
||||||
responseTime,
|
responseTime,
|
||||||
statusCode: response.status,
|
statusCode: response.status,
|
||||||
|
message: http.STATUS_CODES[response.status],
|
||||||
};
|
};
|
||||||
return await this.logAndStoreCheck(checkData, this.db.createCheck);
|
return await this.logAndStoreCheck(checkData, this.db.createCheck);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
const statusCode = error.response?.status || this.NETWORK_ERROR;
|
||||||
|
let message = http.STATUS_CODES[statusCode] || "Network Error";
|
||||||
isAlive = false;
|
isAlive = false;
|
||||||
const checkData = {
|
const checkData = {
|
||||||
monitorId: job.data._id,
|
monitorId: job.data._id,
|
||||||
status: isAlive,
|
status: isAlive,
|
||||||
|
statusCode,
|
||||||
responseTime: error.responseTime,
|
responseTime: error.responseTime,
|
||||||
|
message,
|
||||||
};
|
};
|
||||||
// The server returned a response
|
|
||||||
if (error.response) {
|
|
||||||
checkData.statusCode = error.response.status;
|
|
||||||
} else {
|
|
||||||
checkData.statusCode = this.NETWORK_ERROR;
|
|
||||||
}
|
|
||||||
return await this.logAndStoreCheck(checkData, this.db.createCheck);
|
return await this.logAndStoreCheck(checkData, this.db.createCheck);
|
||||||
} finally {
|
} finally {
|
||||||
this.handleNotification(job, isAlive);
|
this.handleNotification(job, isAlive);
|
||||||
@@ -197,6 +201,8 @@ class NetworkService {
|
|||||||
const checkData = {
|
const checkData = {
|
||||||
monitorId: job.data._id,
|
monitorId: job.data._id,
|
||||||
status: isAlive,
|
status: isAlive,
|
||||||
|
statusCode: response.status,
|
||||||
|
message: http.STATUS_CODES[response.status],
|
||||||
accessibility: (categories.accessibility?.score || 0) * 100,
|
accessibility: (categories.accessibility?.score || 0) * 100,
|
||||||
bestPractices: (categories["best-practices"]?.score || 0) * 100,
|
bestPractices: (categories["best-practices"]?.score || 0) * 100,
|
||||||
seo: (categories.seo?.score || 0) * 100,
|
seo: (categories.seo?.score || 0) * 100,
|
||||||
@@ -213,9 +219,13 @@ class NetworkService {
|
|||||||
this.logAndStoreCheck(checkData, this.db.createPageSpeedCheck);
|
this.logAndStoreCheck(checkData, this.db.createPageSpeedCheck);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
isAlive = false;
|
isAlive = false;
|
||||||
|
const statusCode = error.response?.status || this.NETWORK_ERROR;
|
||||||
|
const message = http.STATUS_CODES[statusCode] || "Network Error";
|
||||||
const checkData = {
|
const checkData = {
|
||||||
monitorId: job.data._id,
|
monitorId: job.data._id,
|
||||||
status: isAlive,
|
status: isAlive,
|
||||||
|
statusCode,
|
||||||
|
message,
|
||||||
accessibility: 0,
|
accessibility: 0,
|
||||||
bestPractices: 0,
|
bestPractices: 0,
|
||||||
seo: 0,
|
seo: 0,
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ const errorMessages = {
|
|||||||
JOB_QUEUE_WORKER_CLOSE: "Error closing worker",
|
JOB_QUEUE_WORKER_CLOSE: "Error closing worker",
|
||||||
JOB_QUEUE_DELETE_JOB: "Job not found in queue",
|
JOB_QUEUE_DELETE_JOB: "Job not found in queue",
|
||||||
JOB_QUEUE_OBLITERATE: "Error obliterating queue",
|
JOB_QUEUE_OBLITERATE: "Error obliterating queue",
|
||||||
|
|
||||||
|
// PING Operations
|
||||||
|
PING_CANNOT_RESOLVE: "No response",
|
||||||
};
|
};
|
||||||
|
|
||||||
const successMessages = {
|
const successMessages = {
|
||||||
@@ -88,6 +91,9 @@ const successMessages = {
|
|||||||
//Maintenance Window Controller
|
//Maintenance Window Controller
|
||||||
MAINTENANCE_WINDOW_CREATE: "Maintenance Window created successfully",
|
MAINTENANCE_WINDOW_CREATE: "Maintenance Window created successfully",
|
||||||
MAINTEANCE_WINDOW_GET_BY_USER: "Got Maintenance Windows by User successfully",
|
MAINTEANCE_WINDOW_GET_BY_USER: "Got Maintenance Windows by User successfully",
|
||||||
|
|
||||||
|
//Ping Operations
|
||||||
|
PING_SUCCESS: "Success",
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
Reference in new issue
Block a user