private async Task <bool> TryAddLoadReport( [NotNull] ServiceLocation serviceLocation, TimeSpan workerResponseTimeout, [NotNull] ConcurrentBag <QualifiedService> loadReportsByService) { Channel channel = GetChannel(serviceLocation); try { // Check for health first, it might be that the process is running but we have not // started it. if (!await IsHealthy(serviceLocation, channel, workerResponseTimeout)) { return(false); } LoadReportResponse loadReportResponse = await GetLoadReport(serviceLocation, channel, workerResponseTimeout); ProcessUtils.EnsureThreadIdInName(); if (loadReportResponse.ServerStats.RequestCapacity == 0) { _logger.LogDebug( "Service location {serviceLocation} reports 0 capacity. It is ignored.", serviceLocation); return(false); } var qualifiedLocation = new QualifiedService(serviceLocation, loadReportResponse.ServerStats) { KnownLoadRate = loadReportResponse.KnownLoadRate }; loadReportsByService.Add(qualifiedLocation); return(true); } catch (TimeoutException) { _logger.LogDebug( "Service location {serviceLocation} took longer than {timeout}s. It is ignored.", serviceLocation, workerResponseTimeout.TotalSeconds); } catch (Exception e) { _logger.LogWarning(e, "Error checking service health / load report for {serviceLocation}", serviceLocation); _lastException = e; } return(false); }
protected bool Equals(QualifiedService other) { return(Equals(ServiceLocation, other.ServiceLocation)); }