dedicated autorestart method
This commit is contained in:
@@ -63,10 +63,23 @@ public class ApiServer(string apiUrl) : IApiServer
|
||||
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)
|
||||
{
|
||||
Log.Fatal("Reached maximum auto-restart attempts");
|
||||
Stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
var now = DateTime.Now;
|
||||
if (now - lastRestartAttempt > TimeSpan.FromMinutes(1))
|
||||
@@ -74,11 +87,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
||||
|
||||
restartAttempts += 1;
|
||||
|
||||
Log.Info("Restarting listener");
|
||||
Stop();
|
||||
httpListener = new();
|
||||
Start();
|
||||
Log.Info("Restarted listener");
|
||||
Restart();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -167,7 +176,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
||||
if (ex.ErrorCode == 995 || ex.ErrorCode == 64)
|
||||
{
|
||||
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;
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user