Beispiel #1
0
        public async Task <AggregateHealthRecord> InternalIsHealthyAsync()
        {
            await _semaphoreSlim.WaitAsync();

            try
            {
                if (HealthRecords.IsEmpty)
                {
                    return(null);
                }
                var unHealtyRecords = new List <string>();

                foreach (var item in HealthRecords)
                {
                    if (item.Value.Healty == false)
                    {
                        unHealtyRecords.Add(item.Key);
                    }
                }
                if (unHealtyRecords.Any())
                {
                    return(AggregateHealthRecord.Unhealthy(unHealtyRecords.ToArray()));
                }
                return(AggregateHealthRecord.Healthy());
            }
            finally
            {
                //When the task is ready, release the semaphore. It is vital to ALWAYS release the semaphore when we are ready, or else we will end up with a Semaphore that is forever locked.
                //This is why it is important to do the Release within a try...finally clause; program execution may crash or take a different path, this way you are guaranteed execution
                _semaphoreSlim.Release();
            }
        }
Beispiel #2
0
 public async Task SetHealthAsync(string key, HealthRecord healthRecord)
 {
     HealthRecords[key] = healthRecord;
     _aggregateRecord   = await InternalIsHealthyAsync();
 }
Beispiel #3
0
 public HealthCheckStore()
 {
     HealthRecords    = new ConcurrentDictionary <string, HealthRecord>();
     _aggregateRecord = AggregateHealthRecord.Unhealthy(new [] { "" });
 }