Hero-admin: voortgangsindicator voor foto's die worden verwerkt, mislukt-melding met opnieuw proberen
Spinner per foto zonder varianten, totaal met voortgangsbalk (aria-valuenow/max), uitleg dat de hero al is opgeslagen, bij 3 mislukte pogingen een melding met 'Opnieuw proberen' (POST /hero/images/{id}/retry; foutstatus staat in het geheugen van de renderer). Test dat een refetch van 5 s onopgeslagen wijzigingen niet overschrijft.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,20 @@ public sealed class HeroRenderSignal
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>How often the renderer may try an image before it gives up on it (until a retry or a restart).</summary>
|
||||
public const int MaxAttempts = 3;
|
||||
|
||||
private readonly System.Collections.Concurrent.ConcurrentDictionary<Guid, int> _failures = new();
|
||||
|
||||
public int RecordFailure(Guid imageId) => _failures.AddOrUpdate(imageId, 1, (_, n) => n + 1);
|
||||
|
||||
public bool IsGivenUp(Guid imageId) => _failures.TryGetValue(imageId, out var n) && n >= MaxAttempts;
|
||||
|
||||
public IReadOnlySet<Guid> GivenUp() => _failures.Where(f => f.Value >= MaxAttempts).Select(f => f.Key).ToHashSet();
|
||||
|
||||
/// <summary>Forgets the failures of an image (after a success, a retry or a new upload of the same photo).</summary>
|
||||
public void Reset(Guid imageId) => _failures.TryRemove(imageId, out _);
|
||||
|
||||
/// <summary>Waits for a signal or for the timeout, whichever comes first.</summary>
|
||||
public Task<bool> WaitAsync(TimeSpan timeout, CancellationToken cancellationToken) => _signal.WaitAsync(timeout, cancellationToken);
|
||||
}
|
||||
@@ -33,8 +47,6 @@ public sealed class HeroRenderSignal
|
||||
/// </summary>
|
||||
public sealed class HeroRenderService(IServiceScopeFactory scopes, HeroRenderSignal signal, ILogger<HeroRenderService> logger) : BackgroundService
|
||||
{
|
||||
private const int MaxAttempts = 3;
|
||||
private readonly Dictionary<Guid, int> _failures = [];
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
@@ -58,7 +70,7 @@ public sealed class HeroRenderService(IServiceScopeFactory scopes, HeroRenderSig
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
var skip = _failures.Where(f => f.Value >= MaxAttempts).Select(f => f.Key).ToHashSet();
|
||||
var skip = signal.GivenUp();
|
||||
Guid? handled = null;
|
||||
try
|
||||
{
|
||||
@@ -67,8 +79,8 @@ public sealed class HeroRenderService(IServiceScopeFactory scopes, HeroRenderSig
|
||||
}
|
||||
catch (HeroImageRenderException failure)
|
||||
{
|
||||
var attempts = _failures[failure.ImageId] = _failures.GetValueOrDefault(failure.ImageId) + 1;
|
||||
logger.LogError(failure.InnerException, "Cutting the variants of hero image {ImageId} failed (attempt {Attempt} of {Max}).", failure.ImageId, attempts, MaxAttempts);
|
||||
var attempts = signal.RecordFailure(failure.ImageId);
|
||||
logger.LogError(failure.InnerException, "Cutting the variants of hero image {ImageId} failed (attempt {Attempt} of {Max}).", failure.ImageId, attempts, HeroRenderSignal.MaxAttempts);
|
||||
await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
|
||||
continue;
|
||||
}
|
||||
@@ -83,7 +95,7 @@ public sealed class HeroRenderService(IServiceScopeFactory scopes, HeroRenderSig
|
||||
return;
|
||||
}
|
||||
|
||||
_failures.Remove(handled.Value);
|
||||
signal.Reset(handled.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user