Fixed scanning issue. Updated worker.
Some checks failed
ci / build-test (push) Has been cancelled
ci / publish-image (push) Has been cancelled

This commit is contained in:
2026-02-14 22:47:19 -05:00
parent 340c62d18b
commit a85989a337
14 changed files with 286 additions and 36 deletions

View File

@@ -5,11 +5,30 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>f4ef1bd4-0cc5-4663-8108-fbb9c9eef5ae</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<None Remove="appsettings.json" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.12" />
<PackageReference Include="Serilog" Version="4.3.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.2" />
</ItemGroup>

View File

@@ -2,7 +2,7 @@
public sealed class ScanOptions
{
public string? Locale { get; init; } = "Japanese"; // maps to your Locale enum
public string Locale { get; init; } = "Japanese"; // maps to your Locale enum
public int? StartPage { get; init; } // if null, resume from checkpoint or 1
public int? EndPage { get; init; } // optional cap
public int? PageSize { get; init; } // override default

View File

@@ -11,16 +11,30 @@ using System.CommandLine;
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
// Build a single configuration pipeline
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();
// Pull the connection string from config (appsettings or secrets or env)
string connectionString = builder.Configuration.GetConnectionString("AppDb")
?? throw new InvalidOperationException("Missing ConnectionStrings:AppDb");
//builder.Services.AddSerilog(o => o
// .WriteTo.Console()
// .MinimumLevel.Information());
builder.Services
.AddApplication()
.AddInfrastructure();
.AddInfrastructure()
.AddMemoryCache();
string connectionString = builder.Configuration.GetConnectionString("AppDb")
?? throw new InvalidOperationException("Missing ConnectionStrings:AppDb2");
//string connectionString = builder.Configuration.GetConnectionString("AppDb")
// ?? throw new InvalidOperationException("Missing ConnectionStrings:AppDb");
builder.Services.AddDbContextFactory<AppDbContext>(optionsBuilder =>
optionsBuilder
@@ -106,4 +120,21 @@ rootCommand.Add(scan);
//rootCommand.SetAction(async (parseResult, cancellationToken) => await rootCommand.InvokeAsync("scan"));
Command schemaDumpCommand = new("schema-dump", "Emit EF model as a full create script (desired.sql)");
schemaDumpCommand.SetAction(async (parseResult, cancellationToken) =>
{
using var host = builder.Build();
await using var scope = host.Services.CreateAsyncScope();
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
var sql = db.Database.GenerateCreateScript();
var outPath = Path.GetFullPath("desired.sql");
await File.WriteAllTextAsync(outPath, sql);
Console.WriteLine($"[OK] Wrote EF model create script to: {outPath}");
});
rootCommand.Add(schemaDumpCommand);
return await rootCommand.Parse(args).InvokeAsync();

View File

@@ -0,0 +1,26 @@
{
"profiles": {
"Scan (JP, 1 page)": {
"commandName": "Project",
"commandLineArgs": "scan --locale Japanese --start 1 --end 1 --pageSize 100",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
},
"workingDirectory": ""
},
"Scan (EN, 3 pages)": {
"commandName": "Project",
"commandLineArgs": "scan --locale English --start 1 --end 3 --pageSize 100",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
}
},
"Watch (JP, every 5m)": {
"commandName": "Project",
"commandLineArgs": "scan --locale Japanese --start 1 --watch --every 00:05:00 --pageSize 100",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -1,8 +1,10 @@
using JSMR.Application.Enums;
using JSMR.Application.Scanning;
using JSMR.Infrastructure.Common.Time;
using JSMR.Worker.Options;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.Globalization;
namespace JSMR.Worker.Services;
@@ -21,6 +23,10 @@ public sealed class PagedScanRunner(
int startPage = options.StartPage
?? (await checkpoints.GetLastPageAsync(options.Locale, cancellationToken)).GetValueOrDefault(0) + 1;
ITimeProvider timeProvider = serviceProvider.GetRequiredService<ITimeProvider>();
log.LogInformation("Scanning on {ScanTime}...", timeProvider.Now().DateTime.ToString(CultureInfo.CurrentCulture));
while (!cancellationToken.IsCancellationRequested)
{
int currentPage = startPage;
@@ -29,7 +35,8 @@ public sealed class PagedScanRunner(
// Iterate until empty page or end reached
for (; !cancellationToken.IsCancellationRequested && (!end.HasValue || currentPage <= end.Value); currentPage++)
{
ScanVoiceWorksHandler handler = serviceProvider.GetRequiredService<ScanVoiceWorksHandler>();
using var scope = serviceProvider.CreateScope();
ScanVoiceWorksHandler handler = scope.ServiceProvider.GetRequiredService<ScanVoiceWorksHandler>();
log.LogInformation("Scanning page {Page} (size {Size}, locale {Locale})…", currentPage, pageSize, locale);

View File

@@ -0,0 +1,11 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"AppDb": "Server=localhost;Port=3306;User=root;Password=password;database=VoiceWorks;SslMode=none"
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}