namespace PrivaPub.Domain.Social { // sends again, now and then, the follow requests still unanswered (FollowService.ResendPending) public sealed class FollowResender(IServiceScopeFactory scopes, ILogger logger) : BackgroundService { static readonly TimeSpan Every = TimeSpan.FromMinutes(15); protected override async Task ExecuteAsync(CancellationToken token) { using var timer = new PeriodicTimer(Every); while (await timer.WaitForNextTickAsync(token)) { try { using var scope = scopes.CreateScope(); var sent = await scope.ServiceProvider.GetRequiredService().ResendPending(DateTime.UtcNow, token); if (sent > 0) logger.LogInformation("Sent {Count} unanswered follow requests again", sent); } catch (Exception ex) when (ex is not OperationCanceledException) { logger.LogWarning(ex, "Unanswered follow requests could not be sent again"); } } } } }