Enhance ShowMetadataApplier with logging for poster retrieval failures
ci / build-backend (push) Successful in 1m37s
ci / build-frontend (push) Successful in 53s
ci / tests (push) Successful in 1m46s
ci / sonar (push) Successful in 4m38s

Updated the ShowMetadataApplier class to include logging for scenarios where show posters are not retrieved successfully. Introduced logging statements to capture warnings when poster URLs are empty or when downloads fail, improving traceability and debugging capabilities. Additionally, updated related tests to ensure proper logging behavior during poster processing.
This commit is contained in:
Leonid Pershin
2026-07-30 02:00:07 +03:00
parent 1758a93011
commit 3fecd81333
7 changed files with 54 additions and 15 deletions
@@ -1,3 +1,4 @@
using Microsoft.Extensions.Logging;
using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Common.Interfaces;
using TeleWave.Application.Common.Models; using TeleWave.Application.Common.Models;
using TeleWave.Application.Library.Genres; using TeleWave.Application.Library.Genres;
@@ -16,7 +17,8 @@ public sealed class ShowMetadataApplier(
IMetadataProviderResolver resolver, IMetadataProviderResolver resolver,
IImageDownloader downloader, IImageDownloader downloader,
IImageStore imageStore, IImageStore imageStore,
GenreMatcher genreMatcher GenreMatcher genreMatcher,
ILogger<ShowMetadataApplier> logger
) )
{ {
/// <summary> /// <summary>
@@ -84,12 +86,28 @@ public sealed class ShowMetadataApplier(
CancellationToken cancellationToken CancellationToken cancellationToken
) )
{ {
// Три исхода — три разные починки, и снаружи они неразличимы: шоу просто остаётся без
// постера. Пишем в лог, какой именно случился.
if (string.IsNullOrEmpty(posterUrl)) if (string.IsNullOrEmpty(posterUrl))
{
logger.LogWarning(
"Постер для «{Show}» не проставлен: источник не вернул ссылку на картинку",
show.Name
);
return null; return null;
}
var downloaded = await downloader.DownloadAsync(posterUrl, cancellationToken); var downloaded = await downloader.DownloadAsync(posterUrl, cancellationToken);
if (downloaded is null) if (downloaded is null)
{
// Подробности (статус, исключение) пишет сам загрузчик.
logger.LogWarning(
"Постер для «{Show}» не проставлен: {Url} не скачался",
show.Name,
posterUrl
);
return null; return null;
}
var image = Image.Create(ImageCategory.ShowPoster, downloaded.Extension, show.Name); var image = Image.Create(ImageCategory.ShowPoster, downloaded.Extension, show.Name);
dbContext.Images.Add(image); dbContext.Images.Add(image);
@@ -99,6 +117,11 @@ public sealed class ShowMetadataApplier(
downloaded.Content, downloaded.Content,
cancellationToken cancellationToken
); );
logger.LogInformation(
"Постер для «{Show}» сохранён как изображение {ImageId}",
show.Name,
image.Id
);
return image.Id; return image.Id;
} }
} }
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging.Abstractions;
using NSubstitute; using NSubstitute;
using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Common.Interfaces;
using TeleWave.Application.Library.Collections.AddShowsToCollection; using TeleWave.Application.Library.Collections.AddShowsToCollection;
@@ -98,7 +99,8 @@ public class AddShowsToCollectionTests
resolver, resolver,
Substitute.For<IImageDownloader>(), Substitute.For<IImageDownloader>(),
Substitute.For<IImageStore>(), Substitute.For<IImageStore>(),
new GenreMatcher(db) new GenreMatcher(db),
NullLogger<ShowMetadataApplier>.Instance
) )
).Handle(new EnrichShowsMetadataCommand([Guid.NewGuid()], "tmdb"), CancellationToken.None); ).Handle(new EnrichShowsMetadataCommand([Guid.NewGuid()], "tmdb"), CancellationToken.None);
@@ -130,7 +132,8 @@ public class AddShowsToCollectionTests
resolver, resolver,
Substitute.For<IImageDownloader>(), Substitute.For<IImageDownloader>(),
Substitute.For<IImageStore>(), Substitute.For<IImageStore>(),
new GenreMatcher(db) new GenreMatcher(db),
NullLogger<ShowMetadataApplier>.Instance
) )
).Handle(new EnrichShowsMetadataCommand([clip.Id], "tmdb"), CancellationToken.None); ).Handle(new EnrichShowsMetadataCommand([clip.Id], "tmdb"), CancellationToken.None);
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging.Abstractions;
using NSubstitute; using NSubstitute;
using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Common.Interfaces;
using TeleWave.Application.Library.Genres; using TeleWave.Application.Library.Genres;
@@ -62,7 +63,8 @@ public class ImportMoviesTests
resolver, resolver,
Substitute.For<IImageDownloader>(), Substitute.For<IImageDownloader>(),
Substitute.For<IImageStore>(), Substitute.For<IImageStore>(),
new GenreMatcher(db) new GenreMatcher(db),
NullLogger<ShowMetadataApplier>.Instance
); );
var result = await new ImportMoviesCommandHandler( var result = await new ImportMoviesCommandHandler(
@@ -296,7 +298,8 @@ public class ImportMoviesTests
resolver, resolver,
Substitute.For<IImageDownloader>(), Substitute.For<IImageDownloader>(),
Substitute.For<IImageStore>(), Substitute.For<IImageStore>(),
new GenreMatcher(db) new GenreMatcher(db),
NullLogger<ShowMetadataApplier>.Instance
); );
var result = await new AutoAttachMovieCommandHandler( var result = await new AutoAttachMovieCommandHandler(
db, db,
@@ -346,7 +349,8 @@ public class ImportMoviesTests
resolver, resolver,
Substitute.For<IImageDownloader>(), Substitute.For<IImageDownloader>(),
Substitute.For<IImageStore>(), Substitute.For<IImageStore>(),
new GenreMatcher(db) new GenreMatcher(db),
NullLogger<ShowMetadataApplier>.Instance
); );
var result = await new AutoAttachMovieCommandHandler( var result = await new AutoAttachMovieCommandHandler(
@@ -1,3 +1,4 @@
using Microsoft.Extensions.Logging.Abstractions;
using NSubstitute; using NSubstitute;
using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Common.Interfaces;
using TeleWave.Application.Library.Genres; using TeleWave.Application.Library.Genres;
@@ -38,7 +39,8 @@ public class MovieImportHandlerTests
resolver, resolver,
Substitute.For<IImageDownloader>(), Substitute.For<IImageDownloader>(),
Substitute.For<IImageStore>(), Substitute.For<IImageStore>(),
new GenreMatcher(db) new GenreMatcher(db),
NullLogger<ShowMetadataApplier>.Instance
); );
[Fact] [Fact]
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging.Abstractions;
using NSubstitute; using NSubstitute;
using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Common.Interfaces;
using TeleWave.Application.Library.Genres; using TeleWave.Application.Library.Genres;
@@ -82,7 +83,8 @@ public class ApplyShowMetadataTests
arranged.Resolver, arranged.Resolver,
Substitute.For<IImageDownloader>(), Substitute.For<IImageDownloader>(),
Substitute.For<IImageStore>(), Substitute.For<IImageStore>(),
new GenreMatcher(db) new GenreMatcher(db),
NullLogger<ShowMetadataApplier>.Instance
) )
); );
@@ -1,3 +1,4 @@
using Microsoft.Extensions.Logging.Abstractions;
using NSubstitute; using NSubstitute;
using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Common.Interfaces;
using TeleWave.Application.Library.Genres; using TeleWave.Application.Library.Genres;
@@ -122,7 +123,8 @@ public class EnrichShowsTests
resolver, resolver,
Substitute.For<IImageDownloader>(), Substitute.For<IImageDownloader>(),
Substitute.For<IImageStore>(), Substitute.For<IImageStore>(),
new GenreMatcher(db) new GenreMatcher(db),
NullLogger<ShowMetadataApplier>.Instance
); );
var result = await new EnrichShowsMetadataCommandHandler(db, resolver, applier).Handle( var result = await new EnrichShowsMetadataCommandHandler(db, resolver, applier).Handle(
@@ -1,4 +1,5 @@
using System.Text; using System.Text;
using Microsoft.Extensions.Logging.Abstractions;
using NSubstitute; using NSubstitute;
using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Common.Interfaces;
using TeleWave.Application.Library.Genres; using TeleWave.Application.Library.Genres;
@@ -97,7 +98,8 @@ public class ShowMetadataApplierTests
resolver, resolver,
Substitute.For<IImageDownloader>(), Substitute.For<IImageDownloader>(),
Substitute.For<IImageStore>(), Substitute.For<IImageStore>(),
new GenreMatcher(db) new GenreMatcher(db),
NullLogger<ShowMetadataApplier>.Instance
); );
var result = await applier.ApplyAsync( var result = await applier.ApplyAsync(
@@ -148,7 +150,8 @@ public class ShowMetadataApplierTests
resolver, resolver,
downloader ?? Substitute.For<IImageDownloader>(), downloader ?? Substitute.For<IImageDownloader>(),
store ?? Substitute.For<IImageStore>(), store ?? Substitute.For<IImageStore>(),
new GenreMatcher(db) new GenreMatcher(db),
NullLogger<ShowMetadataApplier>.Instance
); );
} }