diff --git a/Probe/Index.ts b/Probe/Index.ts index 27743975f7..bb443bc0f8 100644 --- a/Probe/Index.ts +++ b/Probe/Index.ts @@ -1,8 +1,6 @@ -import { - PORT, -} from "./Config"; +import { PORT } from "./Config"; import "./Jobs/Alive"; -import "./Jobs/Monitor/FetchList"; +import "./Jobs/Monitor/FetchList"; import "./Jobs/Monitor/FetchMonitorTest"; import Register from "./Services/Register"; import { PromiseVoidFunction } from "Common/Types/FunctionTypes"; @@ -46,8 +44,6 @@ const init: PromiseVoidFunction = async (): Promise => { logger.error(err); throw err; } - - } catch (err) { logger.error("App Init Failed:"); logger.error(err); diff --git a/Probe/Jobs/Monitor/FetchList.ts b/Probe/Jobs/Monitor/FetchList.ts index 94c12a5d1e..dd878de4ef 100644 --- a/Probe/Jobs/Monitor/FetchList.ts +++ b/Probe/Jobs/Monitor/FetchList.ts @@ -1,4 +1,8 @@ -import { PROBE_INGEST_URL, PROBE_MONITOR_FETCH_LIMIT, PROBE_MONITORING_WORKERS } from "../../Config"; +import { + PROBE_INGEST_URL, + PROBE_MONITOR_FETCH_LIMIT, + PROBE_MONITORING_WORKERS, +} from "../../Config"; import MonitorUtil from "../../Utils/Monitors/Monitor"; import ProbeAPIRequest from "../../Utils/ProbeAPIRequest"; import BaseModel from "Common/Models/DatabaseModels/DatabaseBaseModel/DatabaseBaseModel"; @@ -17,7 +21,6 @@ import Monitor from "Common/Models/DatabaseModels/Monitor"; import { EVERY_MINUTE } from "Common/Utils/CronTime"; import BasicCron from "Common/Server/Utils/BasicCron"; - BasicCron({ jobName: "Probe:MonitorFetchList", options: { @@ -25,7 +28,6 @@ BasicCron({ runOnStartup: true, }, runFunction: async () => { - try { let workers: number = 0; @@ -60,40 +62,34 @@ export default class FetchListAndProbe { public async run(): Promise { logger.debug(`Running worker ${this.workerName}`); - try { - // Sleep randomly between 500 and 1300 milliseconds - // We do this to avoid all workers hitting the server at the same time and fetching the same monitors. - const sleepTime: number = Math.floor(Math.random() * 1300) + 500; - logger.debug( - `Worker ${this.workerName} is sleeping for ${sleepTime}ms`, - ); - await Sleep.sleep(Math.round(sleepTime) % 5000); + try { + // Sleep randomly between 500 and 1300 milliseconds + // We do this to avoid all workers hitting the server at the same time and fetching the same monitors. + const sleepTime: number = Math.floor(Math.random() * 1300) + 500; + logger.debug(`Worker ${this.workerName} is sleeping for ${sleepTime}ms`); + await Sleep.sleep(Math.round(sleepTime) % 5000); - const runTime: Date = OneUptimeDate.getCurrentDate(); + const runTime: Date = OneUptimeDate.getCurrentDate(); - logger.debug(`Probing monitors ${this.workerName}`); + logger.debug(`Probing monitors ${this.workerName}`); - await this.fetchListAndProbe(); + await this.fetchListAndProbe(); - logger.debug(`Probing monitors ${this.workerName} complete`); + logger.debug(`Probing monitors ${this.workerName} complete`); - // if rumTime + 5 seconds is in the future, then this fetchLst either errored out or had no monitors in the list. Either way, wait for 5 seconds and proceed. + // if rumTime + 5 seconds is in the future, then this fetchLst either errored out or had no monitors in the list. Either way, wait for 5 seconds and proceed. - const twoSecondsAdded: Date = OneUptimeDate.addRemoveSeconds( - runTime, - 2, - ); + const twoSecondsAdded: Date = OneUptimeDate.addRemoveSeconds(runTime, 2); - if (OneUptimeDate.isInTheFuture(twoSecondsAdded)) { - logger.debug(`Worker ${this.workerName} is waiting for 1 seconds`); - await Sleep.sleep(1000); - } - } catch (err) { - logger.error(`Error in worker ${this.workerName}`); - logger.error(err); + if (OneUptimeDate.isInTheFuture(twoSecondsAdded)) { + logger.debug(`Worker ${this.workerName} is waiting for 1 seconds`); await Sleep.sleep(1000); } - + } catch (err) { + logger.error(`Error in worker ${this.workerName}`); + logger.error(err); + await Sleep.sleep(1000); + } } private async fetchListAndProbe(): Promise { diff --git a/ProbeIngest/API/Monitor.ts b/ProbeIngest/API/Monitor.ts index 4acd6f1a18..b85dd3ef38 100644 --- a/ProbeIngest/API/Monitor.ts +++ b/ProbeIngest/API/Monitor.ts @@ -328,7 +328,6 @@ router.post( // const moduloBy: number = 10; // const reminder: number = NumberUtil.getRandomNumber(0, 100) % moduloBy; - const count: PositiveNumber = await MonitorProbeService.countBy({ query: { ...getMonitorFetchQuery((req as OneUptimeRequest).probe!.id!), @@ -349,7 +348,6 @@ router.post( skip = NumberUtil.getRandomNumber(0, countNumber - limit); } - const monitorProbes: Array = await MonitorProbeService.findBy({ query: {