Hero: renderer logt per ronde hoeveel foto's wachten op varianten of volledig voorbeeld
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,8 @@ public interface IHeroRepository
|
||||
Task<HeroImage?> GetImageAsync(Guid id, CancellationToken cancellationToken);
|
||||
Task<IReadOnlyList<HeroImage>> GetImagesAsync(IReadOnlyCollection<Guid> ids, CancellationToken cancellationToken);
|
||||
/// <summary>Images whose set is missing or does not match their focus, oldest first (tracked).</summary>
|
||||
Task<int> CountImagesAsync(CancellationToken cancellationToken);
|
||||
|
||||
Task<IReadOnlyList<HeroImage>> GetImagesNeedingRenderAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>Images with a complete set made before the full-frame preview existed (tracked).</summary>
|
||||
@@ -72,6 +74,8 @@ public class HeroRepository(HeroDbContext context) : IHeroRepository
|
||||
return (await context.HeroImages.ToListAsync(cancellationToken)).Where(i => wanted.Contains(i.Id)).ToList();
|
||||
}
|
||||
|
||||
public Task<int> CountImagesAsync(CancellationToken cancellationToken) => context.HeroImages.CountAsync(cancellationToken);
|
||||
|
||||
public async Task<IReadOnlyList<HeroImage>> GetImagesNeedingRenderAsync(CancellationToken cancellationToken)
|
||||
=> (await context.HeroImages.ToListAsync(cancellationToken)).Where(HeroMapping.NeedsRender).OrderBy(i => i.CreatedAt).ToList();
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ public interface IHeroImageService
|
||||
/// <exception cref="ImageRejectedException">The upload is refused; see the code.</exception>
|
||||
Task<HeroImageDto> UploadAsync(Stream upload, long declaredLength, Guid callerId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>How many images exist, how many wait for their variants and how many only lack the full-frame preview (for the log).</summary>
|
||||
Task<(int Total, int NeedRender, int NeedPreview)> GetRenderBacklogAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Records a changed focus (general and optionally per ratio) on a tracked image. Nothing is cut here: the caller saves
|
||||
/// the image together with the hero and then calls <see cref="NotifyPending"/>; the background renderer cuts the new set
|
||||
@@ -188,6 +191,9 @@ public class HeroImageService(
|
||||
signal?.Notify();
|
||||
}
|
||||
|
||||
public async Task<(int Total, int NeedRender, int NeedPreview)> GetRenderBacklogAsync(CancellationToken cancellationToken)
|
||||
=> (await repository.CountImagesAsync(cancellationToken), (await repository.GetImagesNeedingRenderAsync(cancellationToken)).Count, (await repository.GetImagesNeedingPreviewAsync(cancellationToken)).Count);
|
||||
|
||||
public async Task<Guid?> RenderNextPendingAsync(IReadOnlySet<Guid> skip, CancellationToken cancellationToken)
|
||||
{
|
||||
var image = (await repository.GetImagesNeedingRenderAsync(cancellationToken)).FirstOrDefault(i => !skip.Contains(i.Id));
|
||||
|
||||
@@ -58,6 +58,8 @@ public sealed class HeroRenderSignal
|
||||
public sealed class HeroRenderService(IServiceScopeFactory scopes, HeroRenderSignal signal, IOptions<MediaOptions> media, ILogger<HeroRenderService> logger) : BackgroundService
|
||||
{
|
||||
|
||||
private bool _loggedFirstPass;
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
try
|
||||
@@ -91,6 +93,22 @@ public sealed class HeroRenderService(IServiceScopeFactory scopes, HeroRenderSig
|
||||
// An image that failed in this pass waits for the next pass (a minute later or the next wake-up): one difficult photo
|
||||
// must not hold up the others, and it is not retried straight away.
|
||||
var failedInThisPass = new HashSet<Guid>();
|
||||
try
|
||||
{
|
||||
using var scope = scopes.CreateScope();
|
||||
var (total, needRender, needPreview) = await scope.ServiceProvider.GetRequiredService<IHeroImageService>().GetRenderBacklogAsync(stoppingToken);
|
||||
if (needRender + needPreview > 0 || !_loggedFirstPass)
|
||||
{
|
||||
logger.LogInformation("Hero image renderer: {Total} images, {NeedRender} waiting for their variants, {NeedPreview} lacking the full-frame preview.", total, needRender, needPreview);
|
||||
}
|
||||
|
||||
_loggedFirstPass = true;
|
||||
}
|
||||
catch (Exception exception) when (exception is not OperationCanceledException)
|
||||
{
|
||||
logger.LogWarning(exception, "Counting the hero images that wait for the renderer failed.");
|
||||
}
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
var skip = signal.GivenUp().Concat(failedInThisPass).ToHashSet();
|
||||
|
||||
Reference in New Issue
Block a user