Skip to content

Commit

Permalink
move delay to after no message trace
Browse files Browse the repository at this point in the history
  • Loading branch information
aiqiaoy authored Apr 9, 2024
1 parent 3f38bf3 commit 0456a88
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Runner.Listener/MessageListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,6 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
if (message == null)
{
continuousEmptyMessage++;
if (continuousEmptyMessage > 50)
{
// retried more than 50 times in less than 30mins and still getting empty message
// something is not right on the service side, backoff for 15-30s before retry
_getNextMessageRetryInterval = BackoffTimerHelper.GetRandomBackoff(TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(30), _getNextMessageRetryInterval);
Trace.Info("Sleeping for {0} seconds before retrying.", _getNextMessageRetryInterval.TotalSeconds);
await HostContext.Delay(_getNextMessageRetryInterval, token);
}

if (heartbeat.Elapsed > TimeSpan.FromMinutes(30))
{
Trace.Info($"No message retrieved from session '{_session.SessionId}' within last 30 minutes.");
Expand All @@ -380,6 +371,15 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
{
Trace.Verbose($"No message retrieved from session '{_session.SessionId}'.");
}

if (continuousEmptyMessage > 50)
{
// retried more than 50 times in less than 30mins and still getting empty message
// something is not right on the service side, backoff for 15-30s before retry
_getNextMessageRetryInterval = BackoffTimerHelper.GetRandomBackoff(TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(30), _getNextMessageRetryInterval);
Trace.Info("Sleeping for {0} seconds before retrying.", _getNextMessageRetryInterval.TotalSeconds);
await HostContext.Delay(_getNextMessageRetryInterval, token);
}

continue;
}
Expand Down

0 comments on commit 0456a88

Please sign in to comment.