fix probes

This commit is contained in:
Simon Larsen 2023-05-10 18:53:36 +01:00
parent 0c0dd7fd73
commit c973b3b93b
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
6 changed files with 19 additions and 38 deletions

View File

@ -125,6 +125,19 @@ export default class QueryHelper {
);
}
public static lessThanEqualToOrNull(value: number | Date): FindOperator<any> {
const rid: string = Text.generateRandomText(10);
return Raw(
(alias: string) => {
return `${alias} <= :${rid} or ${alias} IS NULL`;
},
{
[rid]: value,
}
);
}
public static greaterThan(value: number | Date): FindOperator<any> {
const rid: string = Text.generateRandomText(10);
return Raw(

View File

@ -4,6 +4,7 @@ import App from 'CommonServer/Utils/StartServer';
import Register from './Services/Register';
import './Jobs/Alive';
import './Jobs/Monitor/FetchList';
const APP_NAME: string = 'probe';

View File

@ -1,37 +0,0 @@
import API from 'Common/Utils/API';
import RunCron from '../Utils/Cron';
import { EVERY_MINUTE } from 'Common/Utils/CronTime';
import { PROBE_API_URL, PROBE_KEY } from '../Config';
import LocalCache from 'CommonServer/Infrastructure/LocalCache';
import URL from 'Common/Types/API/URL';
import logger from 'CommonServer/Utils/Logger';
import Register from '../Services/Register';
RunCron(
'Basic:Monitor',
{
schedule: EVERY_MINUTE,
runOnStartup: false,
},
async () => {
// get a list of monitors from probe-api
// for each monitor, ping and then report back to probe-api
if (!LocalCache.getString('PROBE', 'PROBE_ID')) {
logger.warn(
'Probe is not registered yet. Skipping alive check. Trying to register probe again...'
);
await Register.registerProbe();
return;
}
await API.post(
URL.fromString(PROBE_API_URL.toString()).addRoute('/alive'),
{
probeKey: PROBE_KEY,
probeId: LocalCache.getString('PROBE', 'PROBE_ID'),
}
);
}
);

View File

@ -31,6 +31,8 @@ RunCron(
const monitors: Array<Monitor> = result.data as Array<Monitor>;
console.log('Monitors: ', monitors);
const monitoringPromises: Array<Promise<void>> = [];
for (const monitor of monitors) {

View File

@ -48,7 +48,7 @@ router.post(
query: {
probeId: (req as ProbeExpressRequest).probe!.id!,
isEnabled: true,
nextPingAt: QueryHelper.lessThanEqualTo(
nextPingAt: QueryHelper.lessThanEqualToOrNull(
OneUptimeDate.getCurrentDate()
),
},

View File

@ -5,6 +5,7 @@ import logger from 'CommonServer/Utils/Logger';
import App from 'CommonServer/Utils/StartServer';
import AliveAPI from './API/Alive';
import RegisterAPI from './API/Register';
import MonitorAPI from './API/Monitor';
import Redis from 'CommonServer/Infrastructure/Redis';
@ -14,6 +15,7 @@ const APP_NAME: string = 'probe-api';
app.use([`/${APP_NAME}`, '/'], AliveAPI);
app.use([`/${APP_NAME}`, '/'], RegisterAPI);
app.use([`/${APP_NAME}`, '/'], MonitorAPI);
const init: Function = async (): Promise<void> => {
try {