stabilizaiton work - projects rework for maintenanceability and ui livening
This commit is contained in:
47
src/__Libraries/StellaOps.Provcache/ProvcacheService.Set.cs
Normal file
47
src/__Libraries/StellaOps.Provcache/ProvcacheService.Set.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace StellaOps.Provcache;
|
||||
|
||||
public sealed partial class ProvcacheService
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> SetAsync(ProvcacheEntry entry, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(entry);
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
using var activity = ProvcacheTelemetry.StartSetActivity(entry.VeriKey, entry.Decision.TrustScore);
|
||||
|
||||
try
|
||||
{
|
||||
await _store.SetAsync(entry, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (_options.EnableWriteBehind && _writeBehindQueue is not null)
|
||||
{
|
||||
await _writeBehindQueue.EnqueueAsync(entry, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _repository.UpsertAsync(entry, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
sw.Stop();
|
||||
ProvcacheTelemetry.RecordRequest("set", ProvcacheTelemetry.ResultCreated);
|
||||
ProvcacheTelemetry.RecordLatency("set", sw.Elapsed);
|
||||
|
||||
_logger.LogDebug("Stored cache entry for VeriKey {VeriKey}", entry.VeriKey);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ProvcacheTelemetry.MarkError(activity, ex.Message);
|
||||
ProvcacheTelemetry.RecordRequest("set", ProvcacheTelemetry.ResultError);
|
||||
_logger.LogError(ex, "Error storing cache entry for VeriKey {VeriKey}", entry.VeriKey);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user