public void SetupSubscriptionListener() { var instanceId = RoleEnvironment.CurrentRoleInstance.Id; var instanceNumber = instanceId.Substring(instanceId.LastIndexOf("_")); var environment = RoleEnvironment.IsEmulated ? "dev" : "prod"; var subscriptionName = string.Format("solutionavailable_{0}_{1}", environment, instanceNumber); ServiceBusConfig.Setup(); ServiceBusUtilities.SetupSubscription(subscriptionName); Task.Factory.StartNew(() => { while (true) { var solution = ServiceBusUtilities.SolutionAvailableSubscription.Receive(); if (solution != null) { SolutionsHub.BroadcastSolution(solution); } Thread.Sleep(100); } }); }
private async Task RetryOrFailMessagesAsync(IEnumerable <Message> messages, string errorMessage) { foreach (var message in messages) { var sbMessage = JsonConvert.DeserializeObject <ServiceBusMessage>(Encoding.UTF8.GetString(message.Body)); if (sbMessage.RetryCount >= StartTranscriptionEnvironmentVariables.RetryLimit) { var fileName = StorageConnector.GetFileNameFromUri(sbMessage.Data.Url); var errorFileName = fileName + ".txt"; var retryExceededErrorMessage = $"Exceeded retry count for transcription {fileName} with error message {errorMessage}."; Logger.LogInformation(retryExceededErrorMessage); await StorageConnectorInstance.WriteTextFileToBlobAsync(retryExceededErrorMessage, ErrorReportContaineName, errorFileName, Logger).ConfigureAwait(false); await StorageConnectorInstance.MoveFileAsync( AudioInputContainerName, fileName, StartTranscriptionEnvironmentVariables.ErrorFilesOutputContainer, fileName, Logger).ConfigureAwait(false); } else { sbMessage.RetryCount += 1; var messageDelay = GetMessageDelayTime(sbMessage.RetryCount); var newMessage = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(sbMessage))); await ServiceBusUtilities.SendServiceBusMessageAsync(StartQueueClientInstance, newMessage, Logger, messageDelay).ConfigureAwait(false); } } }
public override bool OnStart() { ServicePointManager.DefaultConnectionLimit = 12; ServiceBusUtilities.Setup(); return(base.OnStart()); }
private void SubscribeToImageMessages() { Log("Subscribing to ImageMessage messages"); _serviceBus = ServiceBus .Setup(ServiceBusUtilities.GetServiceBusCredentials()) .Subscribe <ImageMessage>(this.SaveImageToBlobStorage); Log("Subscribed to ImageMessage messages"); }
/// <summary> /// /// </summary> /// <param name="campaignIdentifier"></param> private static void TriggerTodaysNotification(Guid campaignIdentifier) { var message = new Message { MessageId = Guid.NewGuid().ToString(), }; message.UserProperties.Add(Constants.MessageProperties.Type, Enumerations.AppMessageType.CampaignManagement.ToString()); message.UserProperties.Add(Constants.MessageProperties.CampaignManagement.CampaignIdentifier, campaignIdentifier); message.UserProperties.Add(Constants.MessageProperties.CampaignManagement.EventType, Enumerations.Events.LoadTodaysNotifications.ToString()); ServiceBusUtilities.Send(ConfigurationManager.OmilosIntegrationConnection, ConfigurationManager.CampaignManagementTopicName, message); }
protected override async Task OnCommandCompleted(IReadWriteDataSource dataSource, InviteUser auditTrailEntry, Invitation result) { var emailQueueClient = SendAsEmail ? _queueDataSource.GetQueueClient(_emailQueueName) : null; if (result.EmailBatch != null) { // If we've got an email batch, then we need to put the message onto the queue! var messageToCreate = ServiceBusUtilities.GenerateMessage(new { Metadata = new { baseUrl = _baseUrl } }, result.EmailBatch.ServiceBusMessageId); await emailQueueClient.SendAsync(messageToCreate); // Don't need to expose this to the clients though Invitation.EmailBatch.ServiceBusMessageId = null; } }
private static async Task RetryOrFailJobAsync(TranscriptionStartedMessage message, string error, string jobName, string transcriptionLocation, string subscriptionKey, ILogger log) { message.FailedExecutionCounter += 1; var messageDelayTime = GetMessageDelayTime(message.PollingCounter); if (message.FailedExecutionCounter > FetchTranscriptionEnvironmentVariables.RetryLimit) { await WriteFailedJobLogToStorageAsync(message, error, jobName, log).ConfigureAwait(false); await BatchClient.DeleteTranscriptionAsync(transcriptionLocation, subscriptionKey, log).ConfigureAwait(false); } else { log.LogInformation($"Retrying.."); await ServiceBusUtilities.SendServiceBusMessageAsync(FetchQueueClientInstance, message.CreateMessageString(), log, messageDelayTime).ConfigureAwait(false); } }
protected override async Task OnCommandCompleted(IReadWriteDataSource dataSource, ModifyNotification auditTrailEntry, Notification result) { if (result.EmailBatch != null) { if (_sendEmail) { var emailQueueClient = SendAsEmail ? _queueDataSource.GetQueueClient(_emailQueueName) : null; // If we've created an email batch, then we need to put the message onto the queue! var messageToCreate = ServiceBusUtilities.GenerateMessage(new { Metadata = default(object) }, result.EmailBatch.ServiceBusMessageId, result.StartDate); await emailQueueClient.SendAsync(messageToCreate); } // Make sure we don't expose the queue's message ID - clients don't need to care result.EmailBatch.ServiceBusMessageId = null; } }
public static async Task <bool> GetTranscripts(PostTranscriptionServiceBusMessage serviceBusMessage, ILogger log) { if (serviceBusMessage == null) { throw new ArgumentNullException(nameof(serviceBusMessage)); } var jobName = serviceBusMessage.JobName; var transcriptionId = serviceBusMessage.TranscriptionLocation.Split('/').LastOrDefault(); var transcriptionGuid = new Guid(transcriptionId); log.LogInformation($"Received transcription {transcriptionGuid} with name {jobName} from service bus message."); var serviceBusConnectionString = FetchTranscriptionEnvironmentVariables.FetchTranscriptionServiceBusConnectionString; var reenqueueingTimeInSeconds = serviceBusMessage.ReenqueueingTimeInSeconds; log.LogInformation($"Re-enqueueing time for messages: {reenqueueingTimeInSeconds} seconds."); log.LogInformation($"Subscription location: {serviceBusMessage.Subscription.LocationUri.AbsoluteUri}"); var client = new BatchClient(serviceBusMessage.Subscription.SubscriptionKey, serviceBusMessage.Subscription.LocationUri.AbsoluteUri, log); try { var transcription = await client.GetTranscriptionAsync(transcriptionGuid).ConfigureAwait(false); switch (transcription.Status) { case "Failed": await ProcessFailedTranscriptionAsync(client, transcription, transcriptionGuid, jobName, log).ConfigureAwait(false); break; case "Succeeded": await ProcessSucceededTranscriptionAsync(client, serviceBusMessage, transcriptionGuid, jobName, log).ConfigureAwait(false); break; case "Running": var runningMessage = serviceBusMessage.RetryMessage(); log.LogInformation("Transcription running, retrying message - retry count: " + runningMessage.RetryCount); ServiceBusUtilities.SendServiceBusMessageAsync(serviceBusConnectionString, runningMessage.CreateMessageString(), log, reenqueueingTimeInSeconds).GetAwaiter().GetResult(); break; case "NotStarted": var notStartedMessage = serviceBusMessage.RetryMessage(); var initialDelayInSeconds = serviceBusMessage.InitialDelayInSeconds; // If the transcription is not started yet, the job will take at least length of the audio: var notStartedReenqueueingTime = Math.Max(initialDelayInSeconds, reenqueueingTimeInSeconds); log.LogInformation("Transcription not started, retrying message - retry count: " + notStartedMessage.RetryCount); ServiceBusUtilities.SendServiceBusMessageAsync(serviceBusConnectionString, notStartedMessage.CreateMessageString(), log, notStartedReenqueueingTime).GetAwaiter().GetResult(); break; } } catch (WebException e) { if (BatchClient.IsThrottledOrTimeoutStatusCode(((HttpWebResponse)e.Response).StatusCode)) { var timeoutMessage = serviceBusMessage.RetryMessage(); log.LogInformation("Timeout or throttled, retrying message - retry count: " + timeoutMessage.RetryCount); ServiceBusUtilities.SendServiceBusMessageAsync(serviceBusConnectionString, timeoutMessage.CreateMessageString(), log, reenqueueingTimeInSeconds).GetAwaiter().GetResult(); return(false); } throw; } catch (TimeoutException e) { var timeoutMessage = serviceBusMessage.RetryMessage(); log.LogInformation($"Timeout - re-enqueueing fetch transcription message. Exception message: {e.Message}"); ServiceBusUtilities.SendServiceBusMessageAsync(serviceBusConnectionString, timeoutMessage.CreateMessageString(), log, reenqueueingTimeInSeconds).GetAwaiter().GetResult(); return(false); } return(true); }
public void DoWork() { ServiceBus .Setup(ServiceBusUtilities.GetServiceBusCredentials()) .Subscribe <ImageStoredMessage>(this.OnImageReceived); }
private async Task StartBatchTranscriptionJobAsync(IEnumerable <Message> messages, string jobName) { if (messages == null || !messages.Any()) { Logger.LogError($"Invalid service bus message(s)."); return; } var fetchingDelay = GetInitialFetchingDelay(messages.Count()); var locationString = string.Empty; var serviceBusMessages = messages.Select(message => JsonConvert.DeserializeObject <ServiceBusMessage>(Encoding.UTF8.GetString(message.Body))); try { var properties = GetTranscriptionPropertyBag(); var sasUrls = new List <string>(); var audioFileInfos = new List <AudioFileInfo>(); foreach (var serviceBusMessage in serviceBusMessages) { var sasUrl = StorageConnectorInstance.CreateSas(serviceBusMessage.Data.Url); sasUrls.Add(sasUrl); audioFileInfos.Add(new AudioFileInfo(serviceBusMessage.Data.Url.AbsoluteUri, serviceBusMessage.RetryCount)); } ModelIdentity modelIdentity = null; if (Guid.TryParse(StartTranscriptionEnvironmentVariables.CustomModelId, out var customModelId)) { modelIdentity = ModelIdentity.Create(StartTranscriptionEnvironmentVariables.AzureSpeechServicesRegion, customModelId); } var transcriptionDefinition = TranscriptionDefinition.Create(jobName, "StartByTimerTranscription", Locale, sasUrls, properties, modelIdentity); var transcriptionLocation = await BatchClient.PostTranscriptionAsync( transcriptionDefinition, HostName, SubscriptionKey, Logger).ConfigureAwait(false); Logger.LogInformation($"Location: {transcriptionLocation}"); var transcriptionMessage = new TranscriptionStartedMessage( transcriptionLocation.AbsoluteUri, jobName, Locale, modelIdentity != null, audioFileInfos, 0, 0); await ServiceBusUtilities.SendServiceBusMessageAsync(FetchQueueClientInstance, transcriptionMessage.CreateMessageString(), Logger, fetchingDelay).ConfigureAwait(false); } catch (WebException e) { if (BatchClient.IsThrottledOrTimeoutStatusCode(((HttpWebResponse)e.Response).StatusCode)) { var errorMessage = $"Throttled or timeout while creating post. Error Message: {e.Message}"; Logger.LogError(errorMessage); await RetryOrFailMessagesAsync(messages, errorMessage).ConfigureAwait(false); } else { var errorMessage = $"Start Transcription in job with name {jobName} failed with WebException {e} and message {e.Message}"; Logger.LogError(errorMessage); using (var reader = new StreamReader(e.Response.GetResponseStream())) { var responseMessage = await reader.ReadToEndAsync().ConfigureAwait(false); errorMessage += "\nResponse message:" + responseMessage; } await WriteFailedJobLogToStorageAsync(serviceBusMessages, errorMessage, jobName).ConfigureAwait(false); } throw; } catch (TimeoutException e) { var errorMessage = $"Timeout while creating post, re-enqueueing transcription start. Message: {e.Message}"; Logger.LogError(errorMessage); await RetryOrFailMessagesAsync(messages, errorMessage).ConfigureAwait(false); throw; } catch (Exception e) { var errorMessage = $"Start Transcription in job with name {jobName} failed with exception {e} and message {e.Message}"; Logger.LogError(errorMessage); await WriteFailedJobLogToStorageAsync(serviceBusMessages, errorMessage, jobName).ConfigureAwait(false); throw; } Logger.LogInformation($"Fetch transcription queue successfully informed about job at: {jobName}"); }
public static async Task ProcessTranscriptionJobAsync(TranscriptionStartedMessage serviceBusMessage, ILogger log) { if (serviceBusMessage == null) { throw new ArgumentNullException(nameof(serviceBusMessage)); } var subscriptionKey = FetchTranscriptionEnvironmentVariables.AzureSpeechServicesKey; var jobName = serviceBusMessage.JobName; var transcriptionLocation = serviceBusMessage.TranscriptionLocation; log.LogInformation($"Received transcription at {transcriptionLocation} with name {jobName} from service bus message."); serviceBusMessage.PollingCounter += 1; var messageDelayTime = GetMessageDelayTime(serviceBusMessage.PollingCounter); try { var transcription = await BatchClient.GetTranscriptionAsync(transcriptionLocation, subscriptionKey, log).ConfigureAwait(false); log.LogInformation($"Polled {serviceBusMessage.PollingCounter} time(s) for results in total, delay job for {messageDelayTime.TotalMinutes} minutes if not completed."); switch (transcription.Status) { case "Failed": await ProcessFailedTranscriptionAsync(transcriptionLocation, subscriptionKey, serviceBusMessage, transcription, jobName, log).ConfigureAwait(false); break; case "Succeeded": await ProcessSucceededTranscriptionAsync(transcriptionLocation, subscriptionKey, serviceBusMessage, jobName, log).ConfigureAwait(false); break; case "Running": log.LogInformation($"Transcription running, polling again after {messageDelayTime.TotalMinutes} minutes."); await ServiceBusUtilities.SendServiceBusMessageAsync(FetchQueueClientInstance, serviceBusMessage.CreateMessageString(), log, messageDelayTime).ConfigureAwait(false); break; case "NotStarted": log.LogInformation($"Transcription not started, polling again after {messageDelayTime.TotalMinutes} minutes."); await ServiceBusUtilities.SendServiceBusMessageAsync(FetchQueueClientInstance, serviceBusMessage.CreateMessageString(), log, messageDelayTime).ConfigureAwait(false); break; } } catch (WebException e) { if (e.Response != null && BatchClient.IsThrottledOrTimeoutStatusCode(((HttpWebResponse)e.Response).StatusCode)) { log.LogInformation("Timeout or throttled, retrying message."); await ServiceBusUtilities.SendServiceBusMessageAsync(FetchQueueClientInstance, serviceBusMessage.CreateMessageString(), log, messageDelayTime).ConfigureAwait(false); } else { var errorMessage = $"Fetch Transcription in job with name {jobName} failed with WebException {e} and message {e.Message}."; log.LogError($"{errorMessage}"); await RetryOrFailJobAsync(serviceBusMessage, errorMessage, jobName, transcriptionLocation, subscriptionKey, log).ConfigureAwait(false); } throw; } catch (TimeoutException e) { log.LogInformation($"Timeout - re-enqueueing fetch transcription message. Exception message: {e.Message}"); await ServiceBusUtilities.SendServiceBusMessageAsync(FetchQueueClientInstance, serviceBusMessage.CreateMessageString(), log, messageDelayTime).ConfigureAwait(false); throw; } catch (Exception e) { var errorMessage = $"Fetch Transcription in job with name {jobName} failed with Exception {e} and message {e.Message}."; log.LogError($"{errorMessage}"); await RetryOrFailJobAsync(serviceBusMessage, errorMessage, jobName, transcriptionLocation, subscriptionKey, log).ConfigureAwait(false); throw; } }
private static async Task ProcessFailedTranscriptionAsync(string transcriptionLocation, string subscriptionKey, TranscriptionStartedMessage serviceBusMessage, Transcription transcription, string jobName, ILogger log) { var safeErrorCode = transcription?.Properties?.Error?.Code ?? "unknown"; var safeErrorMessage = transcription?.Properties?.Error?.Message ?? "unknown"; var logMessage = $"Got failed transcription for job {jobName} with error {safeErrorMessage} (Error code: {safeErrorCode})."; log.LogInformation(logMessage); var transcriptionFiles = await BatchClient.GetTranscriptionFilesAsync(transcriptionLocation, subscriptionKey, log).ConfigureAwait(false); var errorReportOutput = logMessage; var reportFile = transcriptionFiles.Values.Where(t => t.Kind == TranscriptionFileKind.TranscriptionReport).FirstOrDefault(); if (reportFile?.Links?.ContentUrl != null) { var reportFileContent = await BatchClient.GetTranscriptionReportFileFromSasAsync(reportFile.Links.ContentUrl, log).ConfigureAwait(false); errorReportOutput += $"\nReport file: \n {JsonConvert.SerializeObject(reportFileContent)}"; } var errorOutputContainer = FetchTranscriptionEnvironmentVariables.ErrorReportOutputContainer; await StorageConnectorInstance.WriteTextFileToBlobAsync(errorReportOutput, errorOutputContainer, $"jobs/{jobName}.txt", log).ConfigureAwait(false); var retryAudioFile = IsRetryableError(safeErrorCode); foreach (var audio in serviceBusMessage.AudioFileInfos) { var fileName = StorageConnector.GetFileNameFromUri(new Uri(audio.FileUrl)); if (retryAudioFile && audio.RetryCount < FetchTranscriptionEnvironmentVariables.RetryLimit) { log.LogInformation($"Retrying transcription with name {fileName} - retry count: {audio.RetryCount}"); var sbMessage = new ServiceBusMessage { Data = new Data { Url = new Uri(audio.FileUrl) }, EventType = "BlobCreated", RetryCount = audio.RetryCount + 1 }; var audioFileMessage = new Message(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(sbMessage))); await ServiceBusUtilities.SendServiceBusMessageAsync(StartQueueClientInstance, audioFileMessage, log, TimeSpan.FromMinutes(1)).ConfigureAwait(false); } else { var message = $"Failed transcription with name {fileName} in job {jobName} after {audio.RetryCount} retries with error: {safeErrorMessage} (Error: {safeErrorCode})."; await StorageConnectorInstance.WriteTextFileToBlobAsync(message, errorOutputContainer, $"{fileName}.txt", log).ConfigureAwait(false); await StorageConnectorInstance.MoveFileAsync( FetchTranscriptionEnvironmentVariables.AudioInputContainer, fileName, FetchTranscriptionEnvironmentVariables.ErrorFilesOutputContainer, fileName, log).ConfigureAwait(false); } } await BatchClient.DeleteTranscriptionAsync(transcriptionLocation, subscriptionKey, log).ConfigureAwait(false); }
public static void Setup() { ServiceBusUtilities.Setup(); }
public static async Task ProcessTranscriptionJobAsync(TranscriptionStartedMessage serviceBusMessage, ILogger log) { if (serviceBusMessage == null) { throw new ArgumentNullException(nameof(serviceBusMessage)); } var subscriptionKey = FetchTranscriptionEnvironmentVariables.AzureSpeechServicesKey; var jobName = serviceBusMessage.JobName; var transcriptionLocation = serviceBusMessage.TranscriptionLocation; log.LogInformation($"Received transcription at {transcriptionLocation} with name {jobName} from service bus message."); var messageDelayTime = GetMessageDelayTime(serviceBusMessage.PollingCounter); serviceBusMessage.PollingCounter += 1; try { var transcription = await BatchClient.GetTranscriptionAsync(transcriptionLocation, subscriptionKey).ConfigureAwait(false); log.LogInformation($"Polled {serviceBusMessage.PollingCounter} time(s) for results in total, delay job for {messageDelayTime.TotalMinutes} minutes if not completed."); switch (transcription.Status) { case "Failed": await ProcessFailedTranscriptionAsync(transcriptionLocation, subscriptionKey, serviceBusMessage, transcription, jobName, log).ConfigureAwait(false); break; case "Succeeded": await ProcessSucceededTranscriptionAsync(transcriptionLocation, subscriptionKey, serviceBusMessage, jobName, log).ConfigureAwait(false); break; case "Running": log.LogInformation($"Transcription running, polling again after {messageDelayTime.TotalMinutes} minutes."); await ServiceBusUtilities.SendServiceBusMessageAsync(FetchServiceBusSender, serviceBusMessage.CreateMessageString(), log, messageDelayTime).ConfigureAwait(false); break; case "NotStarted": log.LogInformation($"Transcription not started, polling again after {messageDelayTime.TotalMinutes} minutes."); await ServiceBusUtilities.SendServiceBusMessageAsync(FetchServiceBusSender, serviceBusMessage.CreateMessageString(), log, messageDelayTime).ConfigureAwait(false); break; } } catch (TransientFailureException e) { await RetryOrFailJobAsync( serviceBusMessage, $"Exception {e} in job {jobName} at {transcriptionLocation}: {e.Message}", jobName, transcriptionLocation, subscriptionKey, log, isThrottled : false).ConfigureAwait(false); } catch (TimeoutException e) { await RetryOrFailJobAsync( serviceBusMessage, $"TimeoutException {e} in job {jobName} at {transcriptionLocation}: {e.Message}", jobName, transcriptionLocation, subscriptionKey, log, isThrottled : false).ConfigureAwait(false); } catch (Exception e) { HttpStatusCode?httpStatusCode = null; if (e is HttpStatusCodeException statusCodeException && statusCodeException.HttpStatusCode.HasValue) { httpStatusCode = statusCodeException.HttpStatusCode.Value; }
public MainWindow() { InitializeComponent(); _bus = ServiceBus.Setup(ServiceBusUtilities.GetServiceBusCredentials()); }
private async Task StartBatchTranscriptionJobAsync(IEnumerable <Message> messages, string jobName, DateTime startDateTime) { if (messages == null || !messages.Any()) { Logger.LogError("Invalid service bus message(s)."); return; } var locationString = string.Empty; var serviceBusMessages = messages.Select(message => JsonConvert.DeserializeObject <ServiceBusMessage>(Encoding.UTF8.GetString(message.Body))); var modelIds = new List <Guid>(); try { var properties = GetTranscriptionPropertyBag(); modelIds = GetModelIds(); var audioFileUrls = new List <string>(); foreach (var serviceBusMessage in serviceBusMessages) { var audioFileUrl = await StorageUtilities.CreateSASAsync(StartTranscriptionEnvironmentVariables.AzureWebJobsStorage, serviceBusMessage.Data.Url, Logger).ConfigureAwait(false); audioFileUrls.Add(audioFileUrl); } var client = new BatchClient(Subscription.SubscriptionKey, Subscription.LocationUri.AbsoluteUri, Logger); var transcriptionLocation = await client.PostTranscriptionAsync( jobName, "StartByTimerTranscription", Locale, properties, audioFileUrls, modelIds).ConfigureAwait(false); Logger.LogInformation($"Location: {transcriptionLocation}"); locationString = transcriptionLocation.ToString(); } catch (WebException e) { if (BatchClient.IsThrottledOrTimeoutStatusCode(((HttpWebResponse)e.Response).StatusCode)) { Logger.LogError($"Throttled or timeout while creating post, re-enqueueing transcription start. Message: {e.Message}"); var startTranscriptionSBConnectionString = StartTranscriptionEnvironmentVariables.StartTranscriptionServiceBusConnectionString; foreach (var message in messages) { ServiceBusUtilities.SendServiceBusMessageAsync(startTranscriptionSBConnectionString, message, Logger, 2).GetAwaiter().GetResult(); } return; } else { Logger.LogError($"Failed with Webexception. Write message for job with name {jobName} to report file."); var errorTxtName = jobName + ".txt"; var exceptionMessage = e.Message; using (var reader = new StreamReader(e.Response.GetResponseStream())) { var responseMessage = await reader.ReadToEndAsync().ConfigureAwait(false); exceptionMessage += "\n" + responseMessage; } await WriteFailedJobLogToStorageAsync(serviceBusMessages, exceptionMessage, jobName).ConfigureAwait(false); return; } } catch (TimeoutException e) { Logger.LogError($"Timeout while creating post, re-enqueueing transcription start. Message: {e.Message}"); var startTranscriptionSBConnectionString = StartTranscriptionEnvironmentVariables.StartTranscriptionServiceBusConnectionString; foreach (var message in messages) { ServiceBusUtilities.SendServiceBusMessageAsync(startTranscriptionSBConnectionString, message, Logger, 2).GetAwaiter().GetResult(); } return; } catch (Exception e) { Logger.LogError($"Failed with Exception {e} and message {e.Message}. Write message for job with name {jobName} to report file."); await WriteFailedJobLogToStorageAsync(serviceBusMessages, e.Message, jobName).ConfigureAwait(false); return; } var reenqueueingTimeInSeconds = MapDatasetSizeToReenqueueingTimeInSeconds(StartTranscriptionEnvironmentVariables.AudioDatasetSize); var transcriptionMessage = new PostTranscriptionServiceBusMessage( Subscription, locationString, jobName, startDateTime.ToString(CultureInfo.InvariantCulture), Locale, modelIds.Any(), StartTranscriptionEnvironmentVariables.AddSentimentAnalysis, StartTranscriptionEnvironmentVariables.AddEntityRedaction, 0, reenqueueingTimeInSeconds, reenqueueingTimeInSeconds); var fetchTranscriptionSBConnectionString = StartTranscriptionEnvironmentVariables.FetchTranscriptionServiceBusConnectionString; Logger.LogInformation($"FetchTranscriptionServiceBusConnectionString from settings: {fetchTranscriptionSBConnectionString}"); try { ServiceBusUtilities.SendServiceBusMessageAsync(fetchTranscriptionSBConnectionString, transcriptionMessage.CreateMessageString(), Logger, reenqueueingTimeInSeconds).GetAwaiter().GetResult(); } catch (Exception e) { Logger.LogError($"Failed with Exception {e} and message {e.Message}. Write message for job with name {jobName} to report file."); await WriteFailedJobLogToStorageAsync(serviceBusMessages, e.Message, jobName).ConfigureAwait(false); } Logger.LogInformation($"Fetch transcription queue informed about job at: {jobName}"); }