in DeviceBridge/Services/SubscriptionScheduler.cs [169:209]
public async Task StartSubscriptionSchedulerAsync()
{
_logger.Info("Started subscription scheduler task");
while (true)
{
try
{
var currentTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
// Start any scheduled connections whose 'not before' timestamp has already expired (up to the maximum batch size).
int startedConnections = 0;
foreach (var entry in _scheduledConnectionsNotBefore)
{
if (currentTime >= entry.Value)
{
_scheduledConnectionsNotBefore.TryRemove(entry.Key, out long _);
var _ = AttemptDeviceConnection(entry.Key).ContinueWith(t => _logger.Error(t.Exception, "Failed to issue scheduled connection attempt for device {deviceId}", entry.Key), TaskContinuationOptions.OnlyOnFaulted);
startedConnections++;
}
if (startedConnections >= _connectionBatchSize)
{
break;
}
}
if (startedConnections > 0)
{
_logger.Info("Subscription scheduler started {connectionCount} connections.", startedConnections);
}
}
catch (Exception e)
{
_logger.Error(e, "Failed to execute subscription scheduler");
}
// Trigger the next execution
await Task.Delay((int)_connectionBatchIntervalMs);
}
}