Skip to content

Commit c86515c

Browse files
committed
https://trello.com/c/UH67DD4M If we have no tokens, make sure we won't continously call the API
1 parent bdbd1b2 commit c86515c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

ProReception.DistributionServerInfrastructure/HostedServices/SignalRHostedService.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,23 @@ private async Task ExecuteStartUp(CancellationToken cancellationToken)
110110

111111
private async Task LoginAndCreateSignalRConnection(CancellationToken cancellationToken)
112112
{
113+
var hasLoggedMissingTokens = false;
114+
while (!cancellationToken.IsCancellationRequested)
115+
{
116+
if (settingsManagerBase.GetTokens() != null)
117+
{
118+
break;
119+
}
120+
121+
if (!hasLoggedMissingTokens)
122+
{
123+
logger.LogInformation("No tokens available. Waiting for user to log in...");
124+
hasLoggedMissingTokens = true;
125+
}
126+
127+
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
128+
}
129+
113130
if (!cancellationToken.IsCancellationRequested)
114131
{
115132
logger.LogInformation("Establishing SignalR connection...");
@@ -183,7 +200,7 @@ private async Task LoginAndCreateSignalRConnection(CancellationToken cancellatio
183200
logger.LogWarning(error, "SignalR connection closed unexpectedly. Attempting to reconnect...");
184201

185202
// Use semaphore to prevent multiple simultaneous reconnection attempts
186-
if (await reconnectLock.WaitAsync(0))
203+
if (await reconnectLock.WaitAsync(0, cancellationToken))
187204
{
188205
try
189206
{

0 commit comments

Comments
 (0)