dedicated autorestart method
This commit is contained in:
@@ -63,10 +63,23 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
Log.Info("Stopped listener");
|
Log.Info("Stopped listener");
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual bool Restart()
|
public virtual void Restart()
|
||||||
|
{
|
||||||
|
Log.Info("Restarting listener");
|
||||||
|
Stop();
|
||||||
|
httpListener = new();
|
||||||
|
Start();
|
||||||
|
Log.Info("Restarted listener");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual bool AutoRestart()
|
||||||
{
|
{
|
||||||
if (restartAttempts > MaxAutoRestartsPerMinute)
|
if (restartAttempts > MaxAutoRestartsPerMinute)
|
||||||
|
{
|
||||||
|
Log.Fatal("Reached maximum auto-restart attempts");
|
||||||
|
Stop();
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var now = DateTime.Now;
|
var now = DateTime.Now;
|
||||||
if (now - lastRestartAttempt > TimeSpan.FromMinutes(1))
|
if (now - lastRestartAttempt > TimeSpan.FromMinutes(1))
|
||||||
@@ -74,11 +87,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
|
|
||||||
restartAttempts += 1;
|
restartAttempts += 1;
|
||||||
|
|
||||||
Log.Info("Restarting listener");
|
Restart();
|
||||||
Stop();
|
|
||||||
httpListener = new();
|
|
||||||
Start();
|
|
||||||
Log.Info("Restarted listener");
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -167,7 +176,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
if (ex.ErrorCode == 995 || ex.ErrorCode == 64)
|
if (ex.ErrorCode == 995 || ex.ErrorCode == 64)
|
||||||
{
|
{
|
||||||
Log.Fatal($"Fatal http error retriving context with code {ex.ErrorCode}", ex);
|
Log.Fatal($"Fatal http error retriving context with code {ex.ErrorCode}", ex);
|
||||||
if (Restart()) // Try restart the server and skip this context
|
if (AutoRestart()) // Try restart the server and skip this context
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user