Skip to content

Commit

Permalink
fix issue with sending probe-id
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed Jun 2, 2023
1 parent e9af3e0 commit 639c4b1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Docs/Probe/CustomProbe.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To begin with you need to create a custom probe in your Project Settings > Probe
To run a probe, please make sure you have docker installed. You can run custom probe by:

```
docker run --name oneuptime-probe -e PROBE_KEY=<probe-key> -e PROBE_ID=<probe-id> -e PROBE_API_URL=https://oneuptime.com/probe-api -d oneuptime/probe
docker run --name oneuptime-probe --network host -e PROBE_KEY=<probe-key> -e PROBE_ID=<probe-id> -e PROBE_API_URL=https://oneuptime.com/probe-api -d oneuptime/probe:release
```

Expand Down
67 changes: 37 additions & 30 deletions Probe/Jobs/Monitor/FetchList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,49 @@ RunCron(
// run a set timeout function randomly between 1 to 5 seconds, so same probes do not hit the server at the same time

setTimeout(async () => {
const result: HTTPResponse<JSONArray> | HTTPErrorResponse =
await API.fetch<JSONArray>(
HTTPMethod.POST,
URL.fromString(PROBE_API_URL.toString()).addRoute(
'/monitor/list'
),
ProbeAPIRequest.getDefaultRequestBody(),
{},
{}
try {
const monitorListUrl: URL = URL.fromString(
PROBE_API_URL.toString()
).addRoute('/monitor/list');

const result: HTTPResponse<JSONArray> | HTTPErrorResponse =
await API.fetch<JSONArray>(
HTTPMethod.POST,
monitorListUrl,
ProbeAPIRequest.getDefaultRequestBody(),
{},
{}
);

const monitors: Array<Monitor> = JSONFunctions.fromJSONArray(
result.data as JSONArray,
Monitor
);

const monitors: Array<Monitor> = JSONFunctions.fromJSONArray(
result.data as JSONArray,
Monitor
);
const monitoringPromises: Array<Promise<void>> = [];

const monitoringPromises: Array<Promise<void>> = [];
for (const monitor of monitors) {
const promise: Promise<void> = new Promise<void>(
(resolve: Function, reject: Function): void => {
MonitorUtil.probeMonitor(monitor)
.then(() => {
resolve();
})
.catch((err: Error) => {
logger.error(err);
reject(err);
});
}
);

for (const monitor of monitors) {
const promise: Promise<void> = new Promise<void>(
(resolve: Function, reject: Function): void => {
MonitorUtil.probeMonitor(monitor)
.then(() => {
resolve();
})
.catch((err: Error) => {
logger.error(err);
reject(err);
});
}
);
monitoringPromises.push(promise);
}

monitoringPromises.push(promise);
await Promise.allSettled(monitoringPromises);
} catch (err) {
logger.error('Error in fetching monitor list');
logger.error(err);
}

await Promise.allSettled(monitoringPromises);
}, Math.floor(Math.random() * 5000) + 1000);
}
);
4 changes: 3 additions & 1 deletion Probe/Utils/ProbeAPIRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export default class ProbeAPIRequest {
public static getDefaultRequestBody(): JSONObject {
return {
probeKey: PROBE_KEY,
probeId: LocalCache.getString('PROBE', 'PROBE_ID'),
probeId:
LocalCache.getString('PROBE', 'PROBE_ID') ||
process.env['PROBE_ID'],
};
}
}

0 comments on commit 639c4b1

Please sign in to comment.