From 1e01edf1b7918dc4dd7e1ff52b24cd616ab6e38f Mon Sep 17 00:00:00 2001 From: Brian Bicknell Date: Sat, 7 Mar 2026 00:03:18 -0500 Subject: [PATCH] Updated worker to show upsert issue messages. --- .../Scanning/Ports/IVoiceWorkUpdater.cs | 2 ++ ...frastructureServiceCollectionExtensions.cs | 4 ++-- .../Ingestion/EnglishVoiceWorkUpdater.cs | 4 ++++ .../Ingestion/VoiceWorkUpdater.cs | 4 ++++ JSMR.Worker/Program.cs | 10 ++++++++-- JSMR.Worker/Services/ScanRunner.cs | 20 ++++++++++++------- JSMR.Worker/UI/CliUi.cs | 20 +++++++++++++++++++ 7 files changed, 53 insertions(+), 11 deletions(-) diff --git a/JSMR.Application/Scanning/Ports/IVoiceWorkUpdater.cs b/JSMR.Application/Scanning/Ports/IVoiceWorkUpdater.cs index 50863e1..44c43a6 100644 --- a/JSMR.Application/Scanning/Ports/IVoiceWorkUpdater.cs +++ b/JSMR.Application/Scanning/Ports/IVoiceWorkUpdater.cs @@ -10,6 +10,8 @@ public interface IVoiceWorkUpdater public class VoiceWorkUpsertResult { + public string ProductId { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; public int? VoiceWorkId { get; set; } public VoiceWorkStatus UpdateStatus { get; set; } public ICollection Issues { get; } = []; diff --git a/JSMR.Infrastructure/DI/InfrastructureServiceCollectionExtensions.cs b/JSMR.Infrastructure/DI/InfrastructureServiceCollectionExtensions.cs index 1b73d4c..27ee427 100644 --- a/JSMR.Infrastructure/DI/InfrastructureServiceCollectionExtensions.cs +++ b/JSMR.Infrastructure/DI/InfrastructureServiceCollectionExtensions.cs @@ -47,11 +47,11 @@ public static class InfrastructureServiceCollectionExtensions services.AddKeyedScoped(Locale.Japanese); services.AddKeyedScoped(Locale.English); - services.AddSingleton(); + services.AddScoped(); services.AddKeyedScoped(Locale.Japanese); services.AddKeyedScoped(Locale.English); - services.AddSingleton(); + services.AddScoped(); services.AddScoped(); diff --git a/JSMR.Infrastructure/Ingestion/EnglishVoiceWorkUpdater.cs b/JSMR.Infrastructure/Ingestion/EnglishVoiceWorkUpdater.cs index 93320ad..a340c4b 100644 --- a/JSMR.Infrastructure/Ingestion/EnglishVoiceWorkUpdater.cs +++ b/JSMR.Infrastructure/Ingestion/EnglishVoiceWorkUpdater.cs @@ -56,6 +56,10 @@ public class EnglishVoiceWorkUpdater(AppDbContext dbContext, ILanguageIdentifier Results: productIds.ToDictionary( productId => productId, productId => new VoiceWorkUpsertResult() + { + ProductId = productId, + Title = ingests.First(x => x.ProductId == productId).Title + } ) ); diff --git a/JSMR.Infrastructure/Ingestion/VoiceWorkUpdater.cs b/JSMR.Infrastructure/Ingestion/VoiceWorkUpdater.cs index 3e366c0..ccc92ce 100644 --- a/JSMR.Infrastructure/Ingestion/VoiceWorkUpdater.cs +++ b/JSMR.Infrastructure/Ingestion/VoiceWorkUpdater.cs @@ -87,6 +87,10 @@ public class VoiceWorkUpdater(AppDbContext dbContext, ITimeProvider timeProvider Results: productIds.ToDictionary( productId => productId, productId => new VoiceWorkUpsertResult() + { + ProductId = productId, + Title = ingests.First(x => x.ProductId == productId).Title + } ) ); diff --git a/JSMR.Worker/Program.cs b/JSMR.Worker/Program.cs index bc8bc26..8c05c36 100644 --- a/JSMR.Worker/Program.cs +++ b/JSMR.Worker/Program.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System.CommandLine; +using System.Text; HostApplicationBuilder builder = Host.CreateApplicationBuilder(args); @@ -16,10 +17,13 @@ builder.Configuration .SetBasePath(builder.Environment.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true) - // Add user secrets (works regardless of environment when optional: true) - .AddUserSecrets(typeof(Program).Assembly, optional: true) .AddEnvironmentVariables(); +if (builder.Environment.IsDevelopment()) +{ + builder.Configuration.AddUserSecrets(typeof(Program).Assembly, optional: true); +} + // Pull the connection string from config (appsettings or secrets or env) string connectionString = builder.Configuration.GetConnectionString("AppDb") ?? throw new InvalidOperationException("Missing ConnectionStrings:AppDb"); @@ -137,4 +141,6 @@ schemaDumpCommand.SetAction(async (parseResult, cancellationToken) => rootCommand.Add(schemaDumpCommand); +Console.OutputEncoding = Encoding.UTF8; + return await rootCommand.Parse(args).InvokeAsync(); \ No newline at end of file diff --git a/JSMR.Worker/Services/ScanRunner.cs b/JSMR.Worker/Services/ScanRunner.cs index a335626..f3eee6a 100644 --- a/JSMR.Worker/Services/ScanRunner.cs +++ b/JSMR.Worker/Services/ScanRunner.cs @@ -77,14 +77,20 @@ public sealed class PagedScanRunner( IEnumerable resultsWithIssues = response.Results.Where(x => x.Issues.Count > 0); // TODO: Later - //foreach (VoiceWorkUpsertResult resultWithIssues in resultsWithIssues) - //{ - // log.LogWarning($"PRoblem with {resultWithIssues.}") - // string messageToDisplay = $"{scannedVoiceWork.ProductId} - {scannedVoiceWork.ProductName} -- {message}"; + foreach (VoiceWorkUpsertResult resultWithIssues in resultsWithIssues) + { + //log.LogWarning($"PRoblem with {resultWithIssues.}") + //string messageToDisplay = $"{scannedVoiceWork.ProductId} - {scannedVoiceWork.ProductName} -- {message}"; - // Console.WriteLine(messageToDisplay); - // messages.Add(messageToDisplay); - //} + //Console.WriteLine(messageToDisplay); + //messages.Add(messageToDisplay); + + string productId = resultWithIssues.ProductId; + string title = resultWithIssues.Title; + string[] messages = [.. resultWithIssues.Issues.Select(x => x.Message)]; + + CliUi.PageErrors($"{productId} - {title}", messages); + } // Save checkpoint await checkpoints.SaveLastPageAsync(options.Locale, currentPage, cancellationToken); diff --git a/JSMR.Worker/UI/CliUi.cs b/JSMR.Worker/UI/CliUi.cs index d054f10..d7b0a4c 100644 --- a/JSMR.Worker/UI/CliUi.cs +++ b/JSMR.Worker/UI/CliUi.cs @@ -30,6 +30,26 @@ public static class CliUi AnsiConsole.Write(panel); } + public static void PageErrors(string productId, string[] messages) + { + if (messages.Length == 0) + return; + + var grid = new Grid().AddColumn(); + + foreach (string message in messages ) + { + grid.AddRow($"[red]{Escape(message)}[/]"); + } + + var panel = new Panel(grid) + .Header($"[bold]{productId}[/]") + .Border(BoxBorder.Rounded) + .Padding(1, 0, 1, 0); + + AnsiConsole.Write(panel); + } + public static void Warning(string message) => AnsiConsole.MarkupLine($"[yellow]⚠ {Escape(message)}[/]");