-
Notifications
You must be signed in to change notification settings - Fork 1.3k
changes to support specific run service URL #2158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using GitHub.DistributedTask.Pipelines; | ||
| using GitHub.DistributedTask.WebApi; | ||
| using GitHub.Services.Common; | ||
| using GitHub.Services.WebApi; | ||
|
|
||
| namespace GitHub.Runner.Common | ||
| { | ||
| [ServiceLocator(Default = typeof(ActionsRunServer))] | ||
| public interface IActionsRunServer : IRunnerService | ||
| { | ||
| Task ConnectAsync(Uri serverUrl, VssCredentials credentials); | ||
|
|
||
| Task<AgentJobRequestMessage> GetJobMessageAsync(string id, CancellationToken token); | ||
| } | ||
|
|
||
| public sealed class ActionsRunServer : RunnerService, IActionsRunServer | ||
| { | ||
| private bool _hasConnection; | ||
| private VssConnection _connection; | ||
| private TaskAgentHttpClient _taskAgentClient; | ||
|
|
||
| public async Task ConnectAsync(Uri serverUrl, VssCredentials credentials) | ||
| { | ||
| _connection = await EstablishVssConnection(serverUrl, credentials, TimeSpan.FromSeconds(100)); | ||
| _taskAgentClient = _connection.GetClient<TaskAgentHttpClient>(); | ||
| _hasConnection = true; | ||
| } | ||
|
|
||
| private void CheckConnection() | ||
| { | ||
| if (!_hasConnection) | ||
| { | ||
| throw new InvalidOperationException($"SetConnection"); | ||
| } | ||
| } | ||
|
|
||
| public Task<AgentJobRequestMessage> GetJobMessageAsync(string id, CancellationToken cancellationToken) | ||
| { | ||
| CheckConnection(); | ||
| var jobMessage = RetryRequest<AgentJobRequestMessage>(async () => | ||
| { | ||
| return await _taskAgentClient.GetJobMessageAsync(id, cancellationToken); | ||
| }, cancellationToken); | ||
|
|
||
| return jobMessage; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -496,16 +496,26 @@ private async Task<int> RunAsync(RunnerSettings settings, bool runOnce = false) | |
| else | ||
| { | ||
| var messageRef = StringUtil.ConvertFromJson<RunnerJobRequestRef>(message.Body); | ||
| Pipelines.AgentJobRequestMessage jobRequestMessage = null; | ||
|
|
||
| // Create connection | ||
| var credMgr = HostContext.GetService<ICredentialManager>(); | ||
| var creds = credMgr.LoadCredentials(); | ||
|
|
||
| var runServer = HostContext.CreateService<IRunServer>(); | ||
| await runServer.ConnectAsync(new Uri(settings.ServerUrl), creds); | ||
| var jobMessage = await runServer.GetJobMessageAsync(messageRef.RunnerRequestId, messageQueueLoopTokenSource.Token); | ||
| if (string.IsNullOrEmpty(messageRef.RunServiceUrl)) | ||
|
yaananth marked this conversation as resolved.
|
||
| { | ||
| var actionsRunServer = HostContext.CreateService<IActionsRunServer>(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👌🏼 I didn't do this btw, this was his how it was before 🤷🏻♂️ I added new code doing the same
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe just a follow-up PR for this change only.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do, thanks! |
||
| await actionsRunServer.ConnectAsync(new Uri(settings.ServerUrl), creds); | ||
| jobRequestMessage = await actionsRunServer.GetJobMessageAsync(messageRef.RunnerRequestId, messageQueueLoopTokenSource.Token); | ||
| } | ||
| else | ||
| { | ||
| var runServer = HostContext.CreateService<IRunServer>(); | ||
| await runServer.ConnectAsync(new Uri(messageRef.RunServiceUrl), creds); | ||
| jobRequestMessage = await runServer.GetJobMessageAsync(messageRef.RunnerRequestId, messageQueueLoopTokenSource.Token); | ||
| } | ||
|
|
||
| jobDispatcher.Run(jobMessage, runOnce); | ||
| jobDispatcher.Run(jobRequestMessage, runOnce); | ||
| if (runOnce) | ||
| { | ||
| Trace.Info("One time used runner received job message."); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.