mirror of
https://github.com/actions/runner.git
synced 2025-12-20 06:29:53 +00:00
print retrieved message
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user