Files
SocialPub/PrivaPub/Domain/Social/FollowResender.cs
T

27 lines
957 B
C#
Raw Normal View History

namespace PrivaPub.Domain.Social
{
// sends again, now and then, the follow requests still unanswered (FollowService.ResendPending)
public sealed class FollowResender(IServiceScopeFactory scopes, ILogger<FollowResender> 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<IFollowService>().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");
}
}
}
}
}