Small refactoring

This commit is contained in:
Tatyana Kostromskaya
2022-06-10 10:18:39 +00:00
committed by GitHub
parent fa0dd79c30
commit 0d1eb56adb
2 changed files with 12 additions and 9 deletions
+9 -6
View File
@@ -13,11 +13,12 @@ using GitHub.Runner.Listener.Configuration;
using GitHub.Runner.Sdk;
using GitHub.Services.WebApi;
using Pipelines = GitHub.DistributedTask.Pipelines;
using GitHub.DistributedTask.Pipelines;
using GitHub.Services.Common;
using System.Runtime.Serialization;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using GitHub.Services.Common;
namespace GitHub.Runner.Listener
{
@@ -483,11 +484,13 @@ namespace GitHub.Runner.Listener
var runServer = HostContext.CreateService<IRunServer>();
await runServer.ConnectAsync(new Uri(settings.ServerUrl), creds);
Func<Task<AgentJobRequestMessage>> getJobRequestMessageAsync = async() => {
return await runServer.GetJobMessageAsync(messageRef.RunnerRequestId);
};
var jobMessage = await RetryHelper<AgentJobRequestMessage>.RetryWithTimeoutAsync(getJobRequestMessageAsync, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10));
var jobMessage = await RetriesHelper<AgentJobRequestMessage>.RetryWithTimeoutAsync(async () =>
{
return await runServer.GetJobMessageAsync(messageRef.RunnerRequestId);
},
TimeSpan.FromSeconds(5),
TimeSpan.FromSeconds(10),
5);
jobDispatcher.Run(jobMessage, runOnce);
if (runOnce)
@@ -6,16 +6,16 @@ namespace GitHub.Services.Common
{
[EditorBrowsable(EditorBrowsableState.Never)]
public static class RetryHelper<T>
public static class RetriesHelper<T>
{
public static async Task<T> RetryWithTimeoutAsync(
Func<Task<T>> retriableAction,
TimeSpan minBackoff,
TimeSpan maxBackoff,
int maxTimeout = 5
int maxTimeoutMinutes = 5
)
{
var remainingTime = TimeSpan.FromMinutes(maxTimeout);
var remainingTime = TimeSpan.FromMinutes(maxTimeoutMinutes);
while (true)
{
try