Skip to content

Commit

Permalink
[IngestionClient] Retry HttpStatusCodeException and do not fail whole…
Browse files Browse the repository at this point in the history
… transcription on transcript download failure (#1734)
  • Loading branch information
HenryvanderVegte authored Nov 10, 2022
1 parent b7cc2b3 commit 86f7da4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static class BatchClient

private static readonly AsyncRetryPolicy RetryPolicy =
Policy
.Handle<HttpRequestException>()
.Handle<Exception>(e => e is HttpStatusCodeException || e is HttpRequestException)
.WaitAndRetryAsync(MaxNumberOfRetries, retryAttempt => TimeSpan.FromSeconds(2));

public static Task<TranscriptionReportFile> GetTranscriptionReportFileFromSasAsync(string sasUri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace FetchTranscriptionFunction
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
Expand Down Expand Up @@ -355,29 +356,40 @@ private async Task ProcessSucceededTranscriptionAsync(string transcriptionLocati
foreach (var resultFile in resultFiles)
{
log.LogInformation($"Getting result for file {resultFile.Name}");
var transcriptionResult = await BatchClient.GetSpeechTranscriptFromSasAsync(resultFile.Links.ContentUrl).ConfigureAwait(false);

if (string.IsNullOrEmpty(transcriptionResult.Source))
try
{
var errorMessage = "Transcription source is unknown, skipping evaluation.";
log.LogError(errorMessage);
var transcriptionResult = await BatchClient.GetSpeechTranscriptFromSasAsync(resultFile.Links.ContentUrl).ConfigureAwait(false);

generalErrorsStringBuilder.AppendLine(errorMessage);
continue;
}
if (string.IsNullOrEmpty(transcriptionResult.Source))
{
var errorMessage = "Transcription source is unknown, skipping evaluation.";
log.LogError(errorMessage);

generalErrorsStringBuilder.AppendLine(errorMessage);
continue;
}

var audioFileName = StorageConnector.GetFileNameFromUri(new Uri(transcriptionResult.Source));
var audioFileInfo = serviceBusMessage.AudioFileInfos.Where(a => a.FileName == audioFileName).First();
var audioFileName = StorageConnector.GetFileNameFromUri(new Uri(transcriptionResult.Source));
var audioFileInfo = serviceBusMessage.AudioFileInfos.Where(a => a.FileName == audioFileName).First();

if (speechTranscriptMappings.ContainsKey(audioFileInfo))
if (speechTranscriptMappings.ContainsKey(audioFileInfo))
{
var errorMessage = $"Duplicate audio file in job, skipping: {audioFileInfo.FileName}.";
log.LogError(errorMessage);
generalErrorsStringBuilder.AppendLine(errorMessage);
continue;
}

speechTranscriptMappings.Add(audioFileInfo, transcriptionResult);
}
catch (Exception e) when (e is HttpStatusCodeException || e is HttpRequestException)
{
var errorMessage = $"Duplicate audio file in job, skipping: {audioFileInfo.FileName}.";
var errorMessage = $"Failed getting speech transcript from content url: {e.Message}";
log.LogError(errorMessage);

generalErrorsStringBuilder.AppendLine(errorMessage);
continue;
}

speechTranscriptMappings.Add(audioFileInfo, transcriptionResult);
}

if (textAnalyticsProvider != null && (FetchTranscriptionEnvironmentVariables.SentimentAnalysisSetting != SentimentAnalysisSetting.None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
}
},
"variables": {
"Version": "v2.0.0",
"Version": "v2.0.1",
"AudioInputContainer": "audio-input",
"AudioProcessedContainer": "audio-processed",
"ErrorFilesOutputContainer": "audio-failed",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
}
},
"variables": {
"Version": "v2.0.0",
"Version": "v2.0.1",
"AudioInputContainer": "audio-input",
"AudioProcessedContainer": "audio-processed",
"ErrorFilesOutputContainer": "audio-failed",
Expand Down

0 comments on commit 86f7da4

Please sign in to comment.