NBloodServerSupervisor/Supervisor/Program.cs

40 lines
1013 B
C#
Raw Normal View History

2020-01-23 21:03:54 +01:00
using System;
using System.Linq;
2020-01-23 21:03:54 +01:00
using System.Threading;
using Model;
namespace Supervisor
{
class Program
{
public static readonly State State = new State();
2020-01-24 12:23:40 +01:00
public static void Main()
2020-01-23 21:03:54 +01:00
{
NBloodServerListener.StartListening();
WebApiListener.StartListening();
2020-01-24 12:23:40 +01:00
PublicServerManager.Start();
2020-01-23 21:03:54 +01:00
PrivateServerManager.Start();
2020-01-27 14:48:53 +01:00
StatisticsManager.Start();
2020-01-23 21:03:54 +01:00
while (true)
{
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 _);
2020-01-23 21:03:54 +01:00
}
}
}
}