mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
Add command execution backoff/timeout
This commit is contained in:
@ -120,6 +120,11 @@ namespace SharedLibraryCore.Database.Models
|
||||
[NotMapped]
|
||||
public string TimeSinceLastConnectionString => (DateTime.UtcNow - LastConnection).HumanizeForCurrentCulture();
|
||||
|
||||
public DateTimeOffset LastCommandExecutionAttempt { get; set; } = DateTimeOffset.MinValue;
|
||||
|
||||
[NotMapped]
|
||||
public int CommandExecutionAttempts { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
// this is kinda dirty, but I need localizable level names
|
||||
public ClientPermission ClientPermission => new ClientPermission
|
||||
|
@ -1339,6 +1339,14 @@ namespace SharedLibraryCore
|
||||
|
||||
return serviceCollection;
|
||||
}
|
||||
|
||||
public static TimeSpan GetExponentialBackoffDelay(int retryCount, int staticDelay = 5)
|
||||
{
|
||||
var maxTimeout = TimeSpan.FromMinutes(2.1);
|
||||
const double factor = 2.0;
|
||||
var delay = Math.Min(staticDelay + Math.Pow(factor, retryCount - 1), maxTimeout.TotalSeconds);
|
||||
return TimeSpan.FromSeconds(delay);
|
||||
}
|
||||
|
||||
public static void ExecuteAfterDelay(TimeSpan duration, Func<CancellationToken, Task> action, CancellationToken token = default) =>
|
||||
ExecuteAfterDelay((int)duration.TotalMilliseconds, action, token);
|
||||
|
Reference in New Issue
Block a user