private void HandleFailures(HttpMessage httpMessage, IPersistentBlob blob) { int retryInterval; if (!httpMessage.HasResponse) { // HttpRequestException // Extend lease time so that it is not picked again for retry. blob.Lease(HttpPipelineHelper.MinimumRetryInterval); } else { switch (httpMessage.Response.Status) { case ResponseStatusCodes.PartialSuccess: // Parse retry-after header // Send Failed Messages To Storage // Delete existing file TrackResponse trackResponse = HttpPipelineHelper.GetTrackResponse(httpMessage); var content = HttpPipelineHelper.GetPartialContentForRetry(trackResponse, httpMessage.Request.Content); if (content != null) { retryInterval = HttpPipelineHelper.GetRetryInterval(httpMessage.Response); blob.Delete(); _storage.SaveTelemetry(content, retryInterval); } break; case ResponseStatusCodes.RequestTimeout: case ResponseStatusCodes.ResponseCodeTooManyRequests: case ResponseStatusCodes.ResponseCodeTooManyRequestsAndRefreshCache: // Extend lease time using retry interval period // so that it is not picked up again before that. retryInterval = HttpPipelineHelper.GetRetryInterval(httpMessage.Response); blob.Lease(retryInterval); break; case ResponseStatusCodes.InternalServerError: case ResponseStatusCodes.BadGateway: case ResponseStatusCodes.ServiceUnavailable: case ResponseStatusCodes.GatewayTimeout: // Extend lease time so that it is not picked up again blob.Lease(HttpPipelineHelper.MinimumRetryInterval); break; default: // Log Non-Retriable Status and don't retry or store; // File will be cleared by maintenance job break; } } }
public void FileBlobTests_Lease() { var testFile = new FileInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())); IPersistentBlob blob = new FileBlob(testFile.FullName); var data = Encoding.UTF8.GetBytes("Hello, World!"); var leasePeriodMilliseconds = 1000; IPersistentBlob blob1 = blob.Write(data); IPersistentBlob leasedBlob = blob1.Lease(leasePeriodMilliseconds); Assert.Contains(".lock", ((FileBlob)leasedBlob).FullPath); blob1.Delete(); Assert.False(testFile.Exists); }
private void HandleFailures(HttpMessage httpMessage, IPersistentBlob blob) { int retryInterval; int statusCode = 0; bool shouldRetry = true; if (!httpMessage.HasResponse) { // HttpRequestException // Extend lease time so that it is not picked again for retry. blob.Lease(HttpPipelineHelper.MinimumRetryInterval); } else { statusCode = httpMessage.Response.Status; switch (statusCode) { case ResponseStatusCodes.PartialSuccess: // Parse retry-after header // Send Failed Messages To Storage // Delete existing file TrackResponse trackResponse = HttpPipelineHelper.GetTrackResponse(httpMessage); var content = HttpPipelineHelper.GetPartialContentForRetry(trackResponse, httpMessage.Request.Content); if (content != null) { retryInterval = HttpPipelineHelper.GetRetryInterval(httpMessage.Response); blob.Delete(); _storage.SaveTelemetry(content, retryInterval); } break; case ResponseStatusCodes.RequestTimeout: case ResponseStatusCodes.ResponseCodeTooManyRequests: case ResponseStatusCodes.ResponseCodeTooManyRequestsAndRefreshCache: // Extend lease time using retry interval period // so that it is not picked up again before that. retryInterval = HttpPipelineHelper.GetRetryInterval(httpMessage.Response); blob.Lease(retryInterval); break; case ResponseStatusCodes.InternalServerError: case ResponseStatusCodes.BadGateway: case ResponseStatusCodes.ServiceUnavailable: case ResponseStatusCodes.GatewayTimeout: // Extend lease time so that it is not picked up again blob.Lease(HttpPipelineHelper.MinimumRetryInterval); break; default: // Log Non-Retriable Status and don't retry or store; // File will be cleared by maintenance job shouldRetry = false; break; } } if (shouldRetry) { AzureMonitorExporterEventSource.Log.WriteWarning("FailedToTransmitFromStorage", $"Error code is {statusCode}: Telemetry is stored offline for retry"); } else { AzureMonitorExporterEventSource.Log.WriteWarning("FailedToTransmitFromStorage", $"Error code is {statusCode}: Telemetry is dropped"); } }