public async Task <bool> TrySetInProcessing(string uowId) { var result = await _repository.GetAsync <UowStatus>(uowId); if (result.Item == null && result.IsSuccessfull) { var retrialWrapper = new UowStatus(currentRetrialCount: 0); await _repository.CreateAsync(new CreateKVRequest <UowStatus> { Item = retrialWrapper, Key = uowId }); } if (result.Item != null && result.IsSuccessfull) { if (result.Item.IsInProcessing) { return(false); } var retrialWrapper = new UowStatus(result.Item.CurrentRetrialCount); await _repository.DeleteAsync(uowId); await _repository.CreateAsync(new CreateKVRequest <UowStatus> { Item = retrialWrapper, Key = uowId }); return(true); } return(false); }
private async Task IncrementRetrialCount(string uowId, Result <UowStatus> result) { var retrialWrapper = new UowStatus(result.Item.CurrentRetrialCount + 1); await _repository.DeleteAsync(uowId); await _repository.CreateAsync(new CreateKVRequest <UowStatus> { Item = retrialWrapper, Key = uowId }); }
public async Task ResetInProcessing(string uowId) { var result = await _repository.GetAsync <UowStatus>(uowId); if (!result.IsSuccessfull) { throw new InvalidOperationException($"Retrieval of uow status information for {uowId} failed with message: {result.ErrorMessage} and code: {result.ErrorCode}"); } var retrialWrapper = new UowStatus(result.Item.CurrentRetrialCount, isInProcessing: false); await _repository.DeleteAsync(uowId); await _repository.CreateAsync(new CreateKVRequest <UowStatus> { Item = retrialWrapper, Key = uowId }); }
public async Task <bool> HasExpiredRetries(string uowId, int maxNumberOfRetries) { if (maxNumberOfRetries == -1) { return(false); } var result = await _repository.GetAsync <UowStatus>(uowId); if (result.Item == null && !string.IsNullOrEmpty(result.ErrorMessage)) { throw new InvalidOperationException($"Retrieval of uow status information for {uowId} failed with message: {result.ErrorMessage} and code: {result.ErrorCode}"); } if (result.Item != null) { if (result.Item.CurrentRetrialCount < maxNumberOfRetries) { await IncrementRetrialCount(uowId, result); return(false); } } else { var retrialWrapper = new UowStatus(currentRetrialCount: 0); await _repository.CreateAsync(new CreateKVRequest <UowStatus> { Item = retrialWrapper, Key = uowId }); return(false); } await _logService.LogInfoAsync(_logId, $"Maximum retrials reached for RingbaUOW by id: {uowId}"); return(true); }