mirror of
https://github.com/actions/runner.git
synced 2025-12-11 04:46:58 +00:00
.
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
using GitHub.DistributedTask.WebApi;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using GitHub.Runner.Common.Util;
|
|
||||||
using GitHub.Services.WebApi;
|
|
||||||
using GitHub.Services.Common;
|
|
||||||
using GitHub.Runner.Sdk;
|
|
||||||
using GitHub.DistributedTask.Pipelines;
|
using GitHub.DistributedTask.Pipelines;
|
||||||
|
using GitHub.DistributedTask.WebApi;
|
||||||
|
using GitHub.Runner.Common.Util;
|
||||||
|
using GitHub.Runner.Sdk;
|
||||||
|
using GitHub.Services.Common;
|
||||||
|
using GitHub.Services.WebApi;
|
||||||
|
|
||||||
namespace GitHub.Runner.Common
|
namespace GitHub.Runner.Common
|
||||||
{
|
{
|
||||||
@@ -17,7 +17,7 @@ namespace GitHub.Runner.Common
|
|||||||
{
|
{
|
||||||
Task ConnectAsync(Uri serverUrl, VssCredentials credentials);
|
Task ConnectAsync(Uri serverUrl, VssCredentials credentials);
|
||||||
|
|
||||||
Task<AgentJobRequestMessage> GetJobMessageAsync(Guid scopeId, Guid hostId, string planType, string planGroup, Guid planId, IList<InstanceRef> instanceRefsJson);
|
Task<AgentJobRequestMessage> GetJobMessageAsync(string id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class RunServer : RunnerService, IRunServer
|
public sealed class RunServer : RunnerService, IRunServer
|
||||||
@@ -28,7 +28,6 @@ namespace GitHub.Runner.Common
|
|||||||
|
|
||||||
public async Task ConnectAsync(Uri serverUrl, VssCredentials credentials)
|
public async Task ConnectAsync(Uri serverUrl, VssCredentials credentials)
|
||||||
{
|
{
|
||||||
// System.Console.WriteLine("RunServer.ConnectAsync");
|
|
||||||
_connection = await EstablishVssConnection(serverUrl, credentials, TimeSpan.FromSeconds(100));
|
_connection = await EstablishVssConnection(serverUrl, credentials, TimeSpan.FromSeconds(100));
|
||||||
_taskAgentClient = _connection.GetClient<TaskAgentHttpClient>();
|
_taskAgentClient = _connection.GetClient<TaskAgentHttpClient>();
|
||||||
_hasConnection = true;
|
_hasConnection = true;
|
||||||
@@ -36,7 +35,6 @@ namespace GitHub.Runner.Common
|
|||||||
|
|
||||||
private async Task<VssConnection> EstablishVssConnection(Uri serverUrl, VssCredentials credentials, TimeSpan timeout)
|
private async Task<VssConnection> EstablishVssConnection(Uri serverUrl, VssCredentials credentials, TimeSpan timeout)
|
||||||
{
|
{
|
||||||
// System.Console.WriteLine("EstablishVssConnection");
|
|
||||||
Trace.Info($"EstablishVssConnection");
|
Trace.Info($"EstablishVssConnection");
|
||||||
Trace.Info($"Establish connection with {timeout.TotalSeconds} seconds timeout.");
|
Trace.Info($"Establish connection with {timeout.TotalSeconds} seconds timeout.");
|
||||||
int attemptCount = 5;
|
int attemptCount = 5;
|
||||||
@@ -69,52 +67,10 @@ namespace GitHub.Runner.Common
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<AgentJobRequestMessage> GetJobMessageAsync(
|
public Task<AgentJobRequestMessage> GetJobMessageAsync(string id)
|
||||||
Guid scopeId,
|
|
||||||
Guid hostId,
|
|
||||||
string planType,
|
|
||||||
string planGroup,
|
|
||||||
Guid planId,
|
|
||||||
IList<InstanceRef> instanceRefsJson)
|
|
||||||
{
|
{
|
||||||
// System.Console.WriteLine("RunServer.GetMessageAsync");
|
|
||||||
CheckConnection();
|
CheckConnection();
|
||||||
return _taskAgentClient.GetJobMessageAsync(scopeId, hostId, planType, planGroup, planId, StringUtil.ConvertToJson(instanceRefsJson, Newtonsoft.Json.Formatting.None));
|
return _taskAgentClient.GetJobMessageAsync(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: move to SDK?
|
|
||||||
[DataContract]
|
|
||||||
public sealed class MessageRef
|
|
||||||
{
|
|
||||||
[DataMember(Name = "url")]
|
|
||||||
public string Url { get; set; }
|
|
||||||
[DataMember(Name = "token")]
|
|
||||||
public string Token { get; set; }
|
|
||||||
[DataMember(Name = "scopeId")]
|
|
||||||
public Guid ScopeId { get; set; }
|
|
||||||
[DataMember(Name = "hostId")]
|
|
||||||
public Guid HostId { get; set; }
|
|
||||||
[DataMember(Name = "planType")]
|
|
||||||
public string PlanType { get; set; }
|
|
||||||
[DataMember(Name = "planGroup")]
|
|
||||||
public string PlanGroup { get; set; }
|
|
||||||
[DataMember(Name = "planId")]
|
|
||||||
public Guid PlanId { get; set; }
|
|
||||||
[DataMember(Name = "instanceRefs")]
|
|
||||||
public InstanceRef[] InstanceRefs { get; set; }
|
|
||||||
[DataMember(Name = "labels")]
|
|
||||||
public string[] Labels { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[DataContract]
|
|
||||||
public sealed class InstanceRef
|
|
||||||
{
|
|
||||||
[DataMember(Name = "name")]
|
|
||||||
public string Name { get; set; }
|
|
||||||
[DataMember(Name = "instanceType")]
|
|
||||||
public string InstanceType { get; set; }
|
|
||||||
[DataMember(Name = "attempt")]
|
|
||||||
public int Attempt { get; set; }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/Runner.Listener/MessageRef.cs
Normal file
11
src/Runner.Listener/MessageRef.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace GitHub.Runner.Listener
|
||||||
|
{
|
||||||
|
[DataContract]
|
||||||
|
public sealed class MessageRef
|
||||||
|
{
|
||||||
|
[DataMember(Name = "id")]
|
||||||
|
public string Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -453,7 +453,7 @@ namespace GitHub.Runner.Listener
|
|||||||
{
|
{
|
||||||
Trace.Info($"Received job message of length {message.Body.Length} from service, with hash '{IOUtil.GetSha256Hash(message.Body)}'");
|
Trace.Info($"Received job message of length {message.Body.Length} from service, with hash '{IOUtil.GetSha256Hash(message.Body)}'");
|
||||||
var jobMessage = StringUtil.ConvertFromJson<Pipelines.AgentJobRequestMessage>(message.Body);
|
var jobMessage = StringUtil.ConvertFromJson<Pipelines.AgentJobRequestMessage>(message.Body);
|
||||||
jobDispatcher.Run(Guid.Empty, jobMessage, runOnce);
|
jobDispatcher.Run(jobMessage, runOnce);
|
||||||
if (runOnce)
|
if (runOnce)
|
||||||
{
|
{
|
||||||
Trace.Info("One time used runner received job message.");
|
Trace.Info("One time used runner received job message.");
|
||||||
@@ -480,10 +480,9 @@ namespace GitHub.Runner.Listener
|
|||||||
// todo: add retries
|
// todo: add retries
|
||||||
var runServer = HostContext.CreateService<IRunServer>();
|
var runServer = HostContext.CreateService<IRunServer>();
|
||||||
await runServer.ConnectAsync(new Uri(settings.ServerUrl), creds);
|
await runServer.ConnectAsync(new Uri(settings.ServerUrl), creds);
|
||||||
var jobMessage = await runServer.GetJobMessageAsync(messageRef.ScopeId, messageRef.HostId, messageRef.PlanType, messageRef.PlanGroup, messageRef.PlanId, messageRef.InstanceRefs);
|
var jobMessage = await runServer.GetJobMessageAsync(messageRef.Id);
|
||||||
|
|
||||||
// todo: Trace.Info($"Received job message of length {message.Body.Length} from service, with hash '{IOUtil.GetSha256Hash(message.Body)}'");
|
jobDispatcher.Run(jobMessage, runOnce);
|
||||||
jobDispatcher.Run(messageRef.HostId, jobMessage, runOnce);
|
|
||||||
if (runOnce)
|
if (runOnce)
|
||||||
{
|
{
|
||||||
Trace.Info("One time used runner received job message.");
|
Trace.Info("One time used runner received job message.");
|
||||||
|
|||||||
@@ -707,20 +707,12 @@ namespace GitHub.DistributedTask.WebApi
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// [Preview API]
|
/// [Preview API]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="scopeId"></param>
|
/// <param name="id">Message ID</param>
|
||||||
/// <param name="planType"></param>
|
|
||||||
/// <param name="planGroup"></param>
|
|
||||||
/// <param name="planId"></param>
|
|
||||||
/// <param name="instanceRefsJson"></param>
|
|
||||||
/// <param name="userState"></param>
|
/// <param name="userState"></param>
|
||||||
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
|
/// <param name="cancellationToken">The cancellation token to cancel operation.</param>
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
public virtual Task<Pipelines.AgentJobRequestMessage> GetJobMessageAsync(
|
public virtual Task<Pipelines.AgentJobRequestMessage> GetJobMessageAsync(
|
||||||
Guid scopeId,
|
string id,
|
||||||
string planType,
|
|
||||||
string planGroup,
|
|
||||||
Guid planId,
|
|
||||||
string instanceRefsJson,
|
|
||||||
object userState = null,
|
object userState = null,
|
||||||
CancellationToken cancellationToken = default)
|
CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
@@ -728,11 +720,7 @@ namespace GitHub.DistributedTask.WebApi
|
|||||||
Guid locationId = new Guid("25adab70-1379-4186-be8e-b643061ebe3a");
|
Guid locationId = new Guid("25adab70-1379-4186-be8e-b643061ebe3a");
|
||||||
|
|
||||||
List<KeyValuePair<string, string>> queryParams = new List<KeyValuePair<string, string>>();
|
List<KeyValuePair<string, string>> queryParams = new List<KeyValuePair<string, string>>();
|
||||||
queryParams.Add("scopeId", scopeId.ToString());
|
queryParams.Add("id", id);
|
||||||
queryParams.Add("planType", planType);
|
|
||||||
queryParams.Add("planGroup", planGroup);
|
|
||||||
queryParams.Add("planId", planId.ToString());
|
|
||||||
queryParams.Add("instanceRefsJson", instanceRefsJson);
|
|
||||||
|
|
||||||
return SendAsync<Pipelines.AgentJobRequestMessage>(
|
return SendAsync<Pipelines.AgentJobRequestMessage>(
|
||||||
httpMethod,
|
httpMethod,
|
||||||
|
|||||||
Reference in New Issue
Block a user