print retrieved message

This commit is contained in:
eric sciple
2022-04-09 00:31:59 +00:00
committed by GitHub
parent 6ec30ea522
commit 25f6cc100f
2 changed files with 44 additions and 26 deletions

View File

@@ -6,6 +6,7 @@ using GitHub.Runner.Common.Util;
using GitHub.Services.WebApi;
using GitHub.Services.Common;
using GitHub.Runner.Sdk;
using System.Net;
using System.Net.Http;
namespace GitHub.Runner.Common
@@ -14,7 +15,7 @@ namespace GitHub.Runner.Common
public interface IBrokerServer : IRunnerService
{
Task ConnectAsync(Uri serverUrl, CancellationToken cancellationToken);
Task<GitHub.DistributedTask.WebApi.TaskAgentMessage> GetMessageAsync(Int32 poolId, Guid sessionId, Int64? lastMessageId, CancellationToken cancellationToken);
Task<string> GetMessageAsync(int poolId, Guid sessionId, long? lastMessageId, CancellationToken cancellationToken);
}
public sealed class BrokerServer : RunnerService, IBrokerServer
@@ -29,10 +30,29 @@ namespace GitHub.Runner.Common
await _httpClient.GetAsync("health", cancellationToken);
}
public async Task<GitHub.DistributedTask.WebApi.TaskAgentMessage> GetMessageAsync(Int32 poolId, Guid sessionId, Int64? lastMessageId, CancellationToken cancellationToken)
public async Task<string> GetMessageAsync(int poolId, Guid sessionId, long? lastMessageId, CancellationToken cancellationToken)
{
await _httpClient.GetAsync("message", cancellationToken);
return null;
var response = await _httpClient.GetAsync("message", cancellationToken);
if (!response.IsSuccessStatusCode)
{
var content = default(string);
try
{
content = await response.Content.ReadAsStringAsync();
}
catch
{
}
var error = $"HTTP {(int)response.StatusCode} {Enum.GetName(typeof(HttpStatusCode), response.StatusCode)}";
if (!string.IsNullOrEmpty(content))
{
error = $"{error}: {content}";
}
throw new Exception(error);
}
return await response.Content.ReadAsStringAsync();
}
}
}