public async Task ProcessCalculation(IAwardCalculator calculator, IAwardCalculationQueueRepository awardCalculationQueueRepository, IErrorLog errorLog) { try { var nextItem = await awardCalculationQueueRepository.Dequeue(); if (string.IsNullOrEmpty(nextItem.Key)) { return; } await calculator.ProcessCalculation(nextItem.Key, nextItem.Value); } catch (Exception exc) { errorLog.Log(exc, ErrorSeverity.Error); } }
public void ProcessCalculation(IAwardCalculator calculator, IAwardCalculationQueueRepository awardCalculationQueueRepository, IErrorLog errorLog) { if (!Monitor.TryEnter(_syncRoot)) { return; } try { var nextItem = awardCalculationQueueRepository.Dequeue(); if (string.IsNullOrEmpty(nextItem.Key)) { return; } calculator.ProcessCalculation(nextItem.Key, nextItem.Value); } catch (Exception exc) { errorLog.Log(exc, ErrorSeverity.Error); } finally { Monitor.Exit(_syncRoot); } }