Added worker app.
All checks were successful
ci / build-test (push) Successful in 2m16s
ci / publish-image (push) Has been skipped

This commit is contained in:
2026-02-01 21:41:23 -05:00
parent c51775592e
commit 340c62d18b
12 changed files with 309 additions and 25 deletions

View File

@@ -5,6 +5,7 @@ using JSMR.Application.Common.Caching;
using JSMR.Application.Creators.Ports;
using JSMR.Application.Creators.Queries.Search.Ports;
using JSMR.Application.Enums;
using JSMR.Application.Integrations.Ports;
using JSMR.Application.Scanning.Ports;
using JSMR.Application.Tags.Ports;
using JSMR.Application.Tags.Queries.Search.Ports;
@@ -21,8 +22,12 @@ using JSMR.Infrastructure.Data.Repositories.Tags;
using JSMR.Infrastructure.Data.Repositories.VoiceWorks;
using JSMR.Infrastructure.Http;
using JSMR.Infrastructure.Ingestion;
using JSMR.Infrastructure.Integrations.DLSite;
using JSMR.Infrastructure.Scanning;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Http.Resilience;
using Polly;
using System.Net;
namespace JSMR.Infrastructure.DI;
@@ -72,29 +77,37 @@ public static class InfrastructureServiceCollectionExtensions
services.AddSingleton<IClock, Clock>();
services.AddSingleton<ITimeProvider, TokyoTimeProvider>();
services.AddHttpClient<IDLSiteClient, DLSiteClient>(httpClient =>
{
httpClient.BaseAddress = new Uri("https://www.dlsite.com/");
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("JSMR/1.0 (+contact@example.com)");
httpClient.Timeout = TimeSpan.FromSeconds(15);
})
.AddResilienceHandler("dlsite", builder =>
{
builder.AddRetry(new HttpRetryStrategyOptions
{
MaxRetryAttempts = 3,
UseJitter = true,
Delay = TimeSpan.FromMilliseconds(200),
BackoffType = DelayBackoffType.Exponential,
ShouldHandle = new PredicateBuilder<HttpResponseMessage>()
.Handle<HttpRequestException>()
.HandleResult(msg =>
msg.StatusCode == (HttpStatusCode)429 ||
(int)msg.StatusCode >= 500)
});
// (Optional) add a circuit breaker:
// builder.AddCircuitBreaker(new HttpCircuitBreakerStrategyOptions
// {
// FailureRatio = 0.2,
// SamplingDuration = TimeSpan.FromSeconds(30),
// MinimumThroughput = 20,
// BreakDuration = TimeSpan.FromSeconds(15)
// });
});
return services;
}
//public static IServiceCollection AddDLSiteClient(this IServiceCollection services)
//{
// var retryPolicy = HttpPolicyExtensions
// .HandleTransientHttpError()
// .OrResult(msg => (int)msg.StatusCode == 429) // Too Many Requests
// .WaitAndRetryAsync(new[]
// {
// TimeSpan.FromMilliseconds(200),
// TimeSpan.FromMilliseconds(500),
// TimeSpan.FromSeconds(1.5)
// });
// services.AddHttpClient<IDLSiteClient, DLSiteClient>(c =>
// {
// c.BaseAddress = new Uri("https://www.dlsite.com/");
// c.DefaultRequestHeaders.UserAgent.ParseAdd("JSMR/1.0 (+contact@example.com)");
// c.Timeout = TimeSpan.FromSeconds(15);
// })
// .AddPolicyHandler(retryPolicy);
// return services;
//}
}