Skip to content

Commit be61175

Browse files
Merge pull request #52 from nullinside-development-group/feat/timeout
feat: increasing time before alerting user
2 parents 6e36547 + 0e0e499 commit be61175

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/SiteMonitor/Constants.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
using System.Reflection;
1+
using System;
2+
using System.Reflection;
23

34
namespace SiteMonitor;
45

56
/// <summary>
67
/// Constants used throughout the file.
78
/// </summary>
89
public class Constants {
10+
/// <summary>
11+
/// The maximum amount of time before alerting the user that we aren't getting chat messages.
12+
/// </summary>
13+
public static readonly TimeSpan MAX_TIME_WITHOUT_CHATS = TimeSpan.FromMinutes(30);
14+
15+
/// <summary>
16+
/// The maximum amount of time before alerting the user that the APIs are down and not automatically coming back up.
17+
/// </summary>
18+
public static readonly TimeSpan MAX_TIME_SERVICE_IS_DOWN = TimeSpan.FromMinutes(5);
19+
920
/// <summary>
1021
/// The version of the application being run right now.
1122
/// </summary>

src/SiteMonitor/ViewModels/MainWindowViewModel.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace SiteMonitor.ViewModels;
2121
/// The view model for the main UI.
2222
/// </summary>
2323
public partial class MainWindowViewModel : ViewModelBase {
24+
private DateTime? _apiDownSince;
2425
[ObservableProperty] private bool _apiUp = true;
2526

2627
[ObservableProperty] private string? _chatTimestamp;
@@ -168,15 +169,17 @@ private async Task PingSite() {
168169
TimeSpan diff = DateTime.Now - time.ToLocalTime();
169170
timestamp = $"{timestamp} ({diff.Hours}h {diff.Minutes}m {diff.Seconds}s ago)";
170171
ChatTimestamp = timestamp;
171-
chatNotUpdating = diff > TimeSpan.FromMinutes(5);
172+
chatNotUpdating = diff > Constants.MAX_TIME_WITHOUT_CHATS;
172173
}
173174
}
174175
else {
175176
ChatTimestamp = null;
176177
chatNotUpdating = true;
177178
}
178179

179-
if ((!WebsiteUp || !ApiUp || !NullUp || chatNotUpdating) && IsMinimized) {
180+
_apiDownSince = !WebsiteUp || !ApiUp || !NullUp ? _apiDownSince ?? DateTime.Now : null;
181+
bool apiNotComingUp = DateTime.Now - _apiDownSince > Constants.MAX_TIME_SERVICE_IS_DOWN;
182+
if ((apiNotComingUp || chatNotUpdating) && IsMinimized) {
180183
WindowState = WindowState.Normal;
181184
}
182185

0 commit comments

Comments
 (0)