mass update.

This commit is contained in:
ruberoid 2025-05-13 21:14:29 +04:00
parent 04fff13fef
commit f0c58e28c9
2 changed files with 15 additions and 6 deletions

View File

@ -9,7 +9,7 @@
<PackageVersion Include="Nocr.TextMatcher.Async.Api.Contracts" />
</ItemGroup>
<ItemGroup Label="Telegram">
<PackageVersion Include="WTelegramClient" Version="3.7.1" />
<PackageVersion Include="WTelegramClient" Version="4.3.4" />
</ItemGroup>
<ItemGroup Label="Rebus">
<PackageVersion Include="Rebus" Version="8.2.2" />

View File

@ -17,6 +17,8 @@ public sealed class UpdateListenerBackgroundService : BackgroundService
private readonly ITelegramClientContainer _telegramClientContainer;
private readonly TelegramRegistry _telegramRegistry;
private DateTimeOffset _activityStartTime = DateTimeOffset.UtcNow;
public UpdateListenerBackgroundService(
ILogger<UpdateListenerBackgroundService> logger,
IServiceProvider serviceProvider,
@ -37,6 +39,14 @@ public sealed class UpdateListenerBackgroundService : BackgroundService
Client? client = null;
while (!stoppingToken.IsCancellationRequested)
{
if (DateTimeOffset.UtcNow - TimeSpan.FromHours(2) < _activityStartTime)
{
_logger.LogInformation("Timeout exceed.");
_activityStartTime = DateTimeOffset.UtcNow;
client = null;
}
if (client == null)
{
_telegramRegistry.Clear();
@ -44,7 +54,7 @@ public sealed class UpdateListenerBackgroundService : BackgroundService
_telegramClientContainer.Initialize();
client = _telegramClientContainer.Client;
client.OnUpdate += HandleUpdates;
client.OnUpdates += HandleUpdates;
var my = await client.LoginUserIfNeeded();
_telegramRegistry.SetMy(my);
@ -52,11 +62,10 @@ public sealed class UpdateListenerBackgroundService : BackgroundService
_telegramRegistry.My.username ??
_telegramRegistry.My.first_name + " " + _telegramRegistry.My.last_name,
_telegramRegistry.My.id);
await _telegramRegistry.Update(client);
}
await Task.Delay(TimeSpan.FromMinutes(5), stoppingToken);
await _telegramRegistry.Update(client);
await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken);
}
}