mirror of
https://github.com/Jetsparrow/jetherald.git
synced 2026-01-20 23:56:08 +03:00
LeakyBucket: Replace Console.Write with ILogger
This commit is contained in:
parent
415979c61e
commit
0c74bc4cea
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace JetHerald
|
namespace JetHerald
|
||||||
@ -9,10 +10,12 @@ namespace JetHerald
|
|||||||
{
|
{
|
||||||
private readonly ConcurrentDictionary<uint, DateTime> expiryDates = new();
|
private readonly ConcurrentDictionary<uint, DateTime> expiryDates = new();
|
||||||
private readonly Options.Timeout config;
|
private readonly Options.Timeout config;
|
||||||
|
private readonly ILogger log;
|
||||||
|
|
||||||
public LeakyBucket(IOptions<Options.Timeout> cfgOptions)
|
public LeakyBucket(IOptions<Options.Timeout> cfgOptions, ILogger<LeakyBucket> log)
|
||||||
{
|
{
|
||||||
config = cfgOptions.Value;
|
config = cfgOptions.Value;
|
||||||
|
this.log = log;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsTimedOut(uint key)
|
public bool IsTimedOut(uint key)
|
||||||
@ -20,7 +23,7 @@ namespace JetHerald
|
|||||||
var now = DateTime.UtcNow;
|
var now = DateTime.UtcNow;
|
||||||
var debtLimit = now.AddSeconds(config.DebtLimitSeconds);
|
var debtLimit = now.AddSeconds(config.DebtLimitSeconds);
|
||||||
var time = expiryDates.GetValueOrDefault(key, now);
|
var time = expiryDates.GetValueOrDefault(key, now);
|
||||||
Console.WriteLine(time);
|
log.LogTrace("{key} had current timedebt of {time}", key, time);
|
||||||
return time > debtLimit;
|
return time > debtLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user