mirror of
https://github.com/CommonLoon102/NBloodServerSupervisor.git
synced 2024-12-22 18:52:44 +01:00
remove crashed servers from the list (#2)
This commit is contained in:
parent
1efbc1784b
commit
8313a88942
@ -8,6 +8,7 @@ namespace Model
|
||||
public class Server
|
||||
{
|
||||
public DateTime SpawnedAtUtc { get; set; } = DateTime.UtcNow;
|
||||
public DateTime LastHeartBeatUtc { get; set; }
|
||||
public int ProcessId { get; set; }
|
||||
public int Port { get; set; }
|
||||
public bool IsStarted { get; set; }
|
||||
|
@ -66,6 +66,7 @@ namespace Supervisor
|
||||
new Server()
|
||||
{
|
||||
Port = packetData.Port,
|
||||
LastHeartBeatUtc = DateTime.UtcNow,
|
||||
IsStarted = packetData.IsStarted,
|
||||
CurrentPlayers = packetData.CurrentPlayers,
|
||||
MaximumPlayers = packetData.MaximumPlayers
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Model;
|
||||
|
||||
@ -17,7 +18,20 @@ namespace Supervisor
|
||||
|
||||
while (true)
|
||||
{
|
||||
Thread.Sleep(TimeSpan.FromSeconds(1));
|
||||
RemoveCrashedServers();
|
||||
Thread.Sleep(TimeSpan.FromSeconds(3));
|
||||
}
|
||||
}
|
||||
|
||||
private static void RemoveCrashedServers()
|
||||
{
|
||||
var crashedServers = State.Servers.Values
|
||||
.Where(s => s.IsStarted && DateTime.UtcNow - s.LastHeartBeatUtc < TimeSpan.FromMinutes(15))
|
||||
.Select(s => s.Port);
|
||||
|
||||
foreach (var port in crashedServers)
|
||||
{
|
||||
State.Servers.TryRemove(port, out _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user