mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-13 12:24:15 +01:00
add some more metrics for files downloading from caches
This commit is contained in:
parent
b5734bdda5
commit
68f0b28e9d
4 changed files with 32 additions and 2 deletions
|
|
@ -105,6 +105,7 @@ public sealed class CachedFileProvider : IDisposable
|
|||
{
|
||||
try
|
||||
{
|
||||
_metrics.IncGauge(MetricsAPI.GaugeFilesDownloadingFromCache);
|
||||
await DownloadTask(hash).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -113,6 +114,7 @@ public sealed class CachedFileProvider : IDisposable
|
|||
}
|
||||
finally
|
||||
{
|
||||
_metrics.DecGauge(MetricsAPI.GaugeFilesDownloadingFromCache);
|
||||
_currentTransfers.Remove(hash, out _);
|
||||
}
|
||||
});
|
||||
|
|
@ -136,9 +138,29 @@ public sealed class CachedFileProvider : IDisposable
|
|||
|
||||
if (_currentTransfers.TryGetValue(hash, out var downloadTask))
|
||||
{
|
||||
await downloadTask.ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
using CancellationTokenSource cts = new();
|
||||
cts.CancelAfter(TimeSpan.FromSeconds(15));
|
||||
_metrics.IncGauge(MetricsAPI.GaugeFilesTasksWaitingForDownloadFromCache);
|
||||
await downloadTask.WaitAsync(cts.Token).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogWarning(e, "Failed while waiting for download task for {hash}", hash);
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_metrics.DecGauge(MetricsAPI.GaugeFilesTasksWaitingForDownloadFromCache);
|
||||
}
|
||||
}
|
||||
|
||||
return GetLocalFileStream(hash);
|
||||
}
|
||||
|
||||
public bool AnyFilesDownloading(List<string> hashes)
|
||||
{
|
||||
return hashes.TrueForAll(_currentTransfers.Keys.Contains);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue