fix(news): use CreateAsyncScope for Playwright service and gracefully handle DbUpdateException on duplicate URLs

This commit is contained in:
2026-08-16 14:11:18 +02:00
parent 2ba54e8057
commit b5cc70c08c
2 changed files with 19 additions and 6 deletions
@@ -61,7 +61,7 @@ public class NewsScraperBackgroundService : BackgroundService
{
try
{
using var scope = _scopeFactory.CreateScope();
await using var scope = _scopeFactory.CreateAsyncScope();
var settings = scope.ServiceProvider.GetRequiredService<ISettingsService>();
bool enabled = await settings.GetSettingAsync(SettingKeys.EnableAutoScraping, stoppingToken);
@@ -82,7 +82,7 @@ public class NewsScraperBackgroundService : BackgroundService
int intervalMinutes = 15;
try
{
using var scope = _scopeFactory.CreateScope();
await using var scope = _scopeFactory.CreateAsyncScope();
var settings = scope.ServiceProvider.GetRequiredService<ISettingsService>();
intervalMinutes = await settings.GetSettingAsync(SettingKeys.ScrapeIntervalMinutes, stoppingToken);
}
@@ -107,7 +107,7 @@ public class NewsScraperBackgroundService : BackgroundService
private async Task RunScrapingCycleAsync(CancellationToken stoppingToken)
{
using var scope = _scopeFactory.CreateScope();
await using var scope = _scopeFactory.CreateAsyncScope();
var dbService = scope.ServiceProvider.GetRequiredService<INewsDbService>();
var discoveryService = scope.ServiceProvider.GetRequiredService<IArticleDiscoveryService>();
var scraperService = scope.ServiceProvider.GetRequiredService<IPlaywrightScraperService>();