Skip to content

Commit b4b1748

Browse files
authored
Merge pull request #33 from AmRo045/dev
Fix health-check bug
2 parents 45cf937 + e92f89a commit b4b1748

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "outline-admin",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"private": true,
55
"scripts": {
66
"compile": "tsc -p tsconfig.scripts.json && tscpaths -p tsconfig.scripts.tscpaths.json -s ./dist -o ./dist",

scripts/health-check.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,22 @@ async function handleUnavailableServer(server: any, errorMessage: string) {
2525
data: { isAvailable: false, lastCheckedAt: now, updatedAt: now }
2626
});
2727

28-
if (!healthCheck.notification) return;
28+
const notificationChannel = healthCheck.notificationChannel;
29+
30+
if (!notificationChannel) {
31+
return;
32+
}
2933

3034
if (healthCheck.notificationSentAt) {
3135
const msSinceLastNotification = Date.now() - new Date(healthCheck.notificationSentAt).getTime();
3236
const cooldownMs = healthCheck.notificationCooldown * 60_000;
3337

34-
if (msSinceLastNotification < cooldownMs) return;
38+
if (msSinceLastNotification < cooldownMs) {
39+
return;
40+
}
3541
}
3642

37-
if (healthCheck.notification === HealthCheckNotificationType.Telegram && server.healthCheck.notificationConfig) {
43+
if (notificationChannel.type === HealthCheckNotificationType.Telegram && notificationChannel.config) {
3844
try {
3945
logger.info("Sending Telegram notification...");
4046
await sendNotificationViaTelegramChannel(server, errorMessage);
@@ -142,7 +148,15 @@ async function checkServerHealth(server: any) {
142148

143149
async function main() {
144150
logger.info("Loading servers from local database...");
145-
const servers = await prisma.server.findMany({ include: { healthCheck: true } });
151+
const servers = await prisma.server.findMany({
152+
include: {
153+
healthCheck: {
154+
include: {
155+
notificationChannel: true
156+
}
157+
}
158+
}
159+
});
146160

147161
logger.info("Starting health checks...");
148162

src/core/definitions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export enum LoggerContext {
88
}
99

1010
export enum HealthCheckNotificationType {
11-
Telegram = "telegram"
11+
Telegram = "Telegram"
1212
}
1313

1414
export type TelegramNotificationChannelConfig = {

0 commit comments

Comments
 (0)