public IEnumerable<ProcessingStepResult> ReceiveLoop() { var backOff = new BackOff(1000); while (rampUpController.CheckHasEnoughWork()) { rampUpController.RampUpIfTooMuchWork(); var message = receive(); if (message != null) { addEvent("Processing started. Time remaining: "+message.ProcessingTime); successfulRead = true; yield return new ProcessingStepResult(message.ProcessingTime, true); } else { rampUpController.Failed(); } if (successfulRead) { process(message); rampUpController.Succeeded(); successfulRead = false; } else { yield return new ProcessingStepResult(backOff.Wait(() => message == null), false); } } }
void ReceiveLoop(object obj) { var backOff = new BackOff(1000); var rampUpController = CreateRampUpController(StartTask); while (!token.IsCancellationRequested && rampUpController.CheckHasEnoughWork()) { bool success; rampUpController.RampUpIfTooMuchWork(); var result = Init(); try { result = Try(result, out success); if (success) { rampUpController.Succeeded(); } else { rampUpController.Failed(); } } finally { Finally(result); } circuitBreaker.Success(); backOff.Wait(() => !success); } }
private void Action(object obj) { var cancellationToken = (CancellationToken)obj; var backOff = new BackOff(1000); while (!cancellationToken.IsCancellationRequested) { var result = new ReceiveResult(); try { if (settings.IsTransactional) { if (settings.DontUseDistributedTransactions) { result = TryReceiveWithNativeTransaction(); } else { result = TryReceiveWithDTCTransaction(); } } else { result = TryReceiveWithNoTransaction(); } } finally { //since we're polling the message will be null when there was nothing in the queue if (result.Message != null) { endProcessMessage(result.Message, result.Exception); } } circuitBreaker.Success(); backOff.Wait(() => result.Message == null); } }
private void Action(object obj) { var cancellationToken = (CancellationToken)obj; var backOff = new BackOff(1000); while (!cancellationToken.IsCancellationRequested) { var result = new ReceiveResult(); try { if (settings.IsTransactional) { if (settings.DontUseDistributedTransactions) { result = TryReceiveWithNativeTransaction(); } else { result = TryReceiveWithDTCTransaction(); } } else { result = TryReceiveWithNoTransaction(); } } finally { //since we're polling the message will be null when there was nothing in the queue if (result.Message != null) endProcessMessage(result.Message, result.Exception); } circuitBreaker.Success(); backOff.Wait(() => result.Message == null); } }