oneuptime/Probe/Index.ts

30 lines
835 B
TypeScript
Raw Normal View History

2022-04-11 13:11:16 +00:00
import 'CommonServer/utils/env';
import 'CommonServer/utils/process';
2021-01-26 13:48:33 +00:00
2022-04-01 20:17:29 +00:00
import asyncSleep from 'await-sleep';
2022-04-26 13:23:33 +00:00
import Main from './Workers/Index';
import config from './Config';
2022-04-10 21:57:14 +00:00
import logger from 'CommonServer/Utils/Logger';
2022-04-14 13:57:52 +00:00
const cronMinuteStartTime: $TSFixMe = Math.floor(Math.random() * 50);
2020-02-24 13:07:26 +00:00
2022-01-18 17:59:51 +00:00
setTimeout(async () => {
2022-04-15 22:14:01 +00:00
// Keep monitoring in an infinate loop.
2022-01-23 19:36:47 +00:00
2022-03-19 17:01:37 +00:00
//eslint-disable-next-line no-constant-condition
2022-01-18 17:59:51 +00:00
while (true) {
2022-02-23 11:38:57 +00:00
try {
2022-02-23 16:07:08 +00:00
await Main.runJob();
2022-02-23 11:38:57 +00:00
} catch (error) {
2022-02-23 15:37:56 +00:00
logger.error(error);
2022-02-23 15:25:35 +00:00
logger.info('Sleeping for 30 seconds...');
2022-02-23 11:38:57 +00:00
await asyncSleep(30 * 1000);
}
2022-01-18 17:59:51 +00:00
}
2022-01-18 16:38:06 +00:00
}, cronMinuteStartTime * 1000);
2022-03-19 17:01:37 +00:00
logger.info(
2022-02-23 15:37:56 +00:00
`Probe with Probe Name ${config.probeName} and Probe Key ${config.probeKey}. OneUptime Probe API URL: ${config.probeApiUrl}`
);