Skip to content

Commit

Permalink
Extend standalone timeout to 2 minutes for GeniusService (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
Smalls1652 authored Jun 20, 2024
1 parent 2fdce3d commit bf6850e
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -214,6 +215,7 @@ coreSongName is not null
// and process the job.
await Task.Delay(5000);
bool isSongLyricsJobFinished = false;
Stopwatch acknowledgedStopwatch = Stopwatch.StartNew();
while (!isSongLyricsJobFinished)
{
using (var songLyricsDbContext = _lyricsAnalyzerDbContextFactory.CreateDbContext())
Expand All @@ -223,6 +225,13 @@ coreSongName is not null
// If the standalone service has not acknowledged the request, throw an exception.
if (!songLyricsRequestJobStatus.StandaloneServiceAcknowledged)
{
if (acknowledgedStopwatch.Elapsed.TotalMinutes < 2)
{
continue;
}

acknowledgedStopwatch.Stop();

_logger.LogWarning("Standalone service has not acknowledged the request. Continuing with the fallback method instead.");

await _queueClientService.QueueClient.DeleteMessageAsync(
Expand All @@ -235,12 +244,18 @@ await _queueClientService.QueueClient.DeleteMessageAsync(
message: "Standalone service has not acknowledged the request. Fallback method is needed."
);
}
else
{
acknowledgedStopwatch.Stop();
}

// If the standalone service indicates that the fallback method is needed, throw an exception.
if (songLyricsRequestJobStatus.FallbackMethodNeeded)
{
_logger.LogWarning("Fallback method is needed. Continuing with the fallback method instead.");

acknowledgedStopwatch.Stop();

throw new SongRequestJobException(
exceptionType: SongRequestJobExceptionType.FallbackMethodNeeded,
message: "Standalone service has indicated that the fallback method is needed."
Expand Down

0 comments on commit bf6850e

Please sign in to comment.