Skip to content

Commit

Permalink
removing unused files and hotfixing the network status job
Browse files Browse the repository at this point in the history
  • Loading branch information
Baalmart committed Oct 9, 2024
1 parent 2ba181b commit 08c268c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 302 deletions.
82 changes: 0 additions & 82 deletions src/device-registry/bin/jobs/check-network-status-job.js

This file was deleted.

26 changes: 13 additions & 13 deletions src/device-registry/bin/jobs/new-check-network-status-job.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ const logger = log4js.getLogger(
const DeviceModel = require("@models/Device");
const cron = require("node-cron");
const { logText } = require("@utils/log");

const BATCH_SIZE = 1000; // Define the size of each batch
const moment = require("moment-timezone");
const TIMEZONE = moment.tz.guess();
const UPTIME_THRESHOLD = 50;

const checkNetworkStatus = async () => {
try {
Expand All @@ -34,15 +35,14 @@ const checkNetworkStatus = async () => {
const { totalDevices, offlineDevicesCount } = result[0];
const offlinePercentage = (offlineDevicesCount / totalDevices) * 100;

if (offlinePercentage > 60) {
if (offlinePercentage > UPTIME_THRESHOLD) {
logText(
`⚠️💔😥 More than 60% of devices are offline: ${offlinePercentage.toFixed(
`⚠️💔😥 More than ${UPTIME_THRESHOLD}% of devices are offline: ${offlinePercentage.toFixed(
2
)}%`
);

logger.warn(
`⚠️💔😥 More than 60% of devices are offline: ${offlinePercentage.toFixed(
`⚠️💔😥 More than ${UPTIME_THRESHOLD}% of devices are offline: ${offlinePercentage.toFixed(
2
)}%`
);
Expand All @@ -52,11 +52,11 @@ const checkNetworkStatus = async () => {
2
)}% offline`
);
// logger.info(
// `✅ Network status is acceptable: ${offlinePercentage.toFixed(
// 2
// )}% offline`
// );
logger.info(

Check warning on line 55 in src/device-registry/bin/jobs/new-check-network-status-job.js

View check run for this annotation

Codecov / codecov/patch

src/device-registry/bin/jobs/new-check-network-status-job.js#L55

Added line #L55 was not covered by tests
`✅ Network status is acceptable: ${offlinePercentage.toFixed(
2
)}% offline`
);
}
} catch (error) {
logText(`Error checking network status: ${error.message}`);
Expand All @@ -66,8 +66,8 @@ const checkNetworkStatus = async () => {
};

logText("Network status job is now running.....");
const schedule = "0 */2 * * *";
const schedule = "30 */2 * * *"; // At minute 30 of every 2nd hour
cron.schedule(schedule, checkNetworkStatus, {
scheduled: true,
timezone: constants.TIMEZONE,
timezone: TIMEZONE,
});
118 changes: 0 additions & 118 deletions src/device-registry/bin/jobs/store-readings-job.js

This file was deleted.

88 changes: 0 additions & 88 deletions src/device-registry/bin/jobs/test/ut_check-network-status-job.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/device-registry/bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const { logText, logObject } = require("@utils/log");
const stringify = require("@utils/stringify");
require("@bin/jobs/store-signals-job");
require("@bin/jobs/new-store-readings-job");
// require("@bin/jobs/new-check-network-status-job");
require("@bin/jobs/new-check-network-status-job");

if (isEmpty(constants.SESSION_SECRET)) {
throw new Error("SESSION_SECRET environment variable not set");
Expand Down

0 comments on commit 08c268c

Please sign in to comment.