simplified conditionals for updating status and sending notifications
This commit is contained in:
1 parent
4d61ecfe35
commit
d2528a694e
1 file changed
+4
-14
@@ -56,22 +56,12 @@ class NetworkService {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (monitor.status === undefined || monitor.status !== isAlive) {
|
||||||
// Two general cases:
|
const oldStatus = monitor.status;
|
||||||
// 1. Monitor status is undefined
|
|
||||||
// 2. Monitor status is defined
|
|
||||||
|
|
||||||
// If the monitor status is undefined, set it's status to isAlive. if isAlive is false, send notification
|
|
||||||
if (monitor.status === undefined) {
|
|
||||||
monitor.status = isAlive;
|
monitor.status = isAlive;
|
||||||
await monitor.save();
|
await monitor.save();
|
||||||
if (isAlive === false) {
|
|
||||||
this.handleNotification(monitor, isAlive);
|
if (oldStatus !== undefined && oldStatus !== isAlive) {
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (monitor.status !== isAlive) {
|
|
||||||
monitor.status = !monitor.status;
|
|
||||||
await monitor.save();
|
|
||||||
this.handleNotification(monitor, isAlive);
|
this.handleNotification(monitor, isAlive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user