Skip to content
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

Handle ForceTokenRefresh message #3133

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Runner.Listener/BrokerMessageListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
}

// re-create VssConnection before next retry
await RefreshBrokerConnection();
await RefreshBrokerConnectionAsync();

Trace.Info("Sleeping for {0} seconds before retrying.", _getNextMessageRetryInterval.TotalSeconds);
await HostContext.Delay(_getNextMessageRetryInterval, token);
Expand Down Expand Up @@ -303,6 +303,11 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
}
}

public async Task RefreshListenerTokenAsync(CancellationToken cancellationToken)
{
await RefreshBrokerConnectionAsync();
}

public async Task DeleteMessageAsync(TaskAgentMessage message)
{
await Task.CompletedTask;
Expand Down Expand Up @@ -398,7 +403,7 @@ ex is AccessDeniedException ||
}
}

private async Task RefreshBrokerConnection()
private async Task RefreshBrokerConnectionAsync()
{
var configManager = HostContext.GetService<IConfigurationManager>();
_settings = configManager.LoadSettings();
Expand Down
7 changes: 7 additions & 0 deletions src/Runner.Listener/MessageListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public interface IMessageListener : IRunnerService
Task DeleteSessionAsync();
Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token);
Task DeleteMessageAsync(TaskAgentMessage message);

Task RefreshListenerTokenAsync(CancellationToken token);
void OnJobStatus(object sender, JobStatusEventArgs e);
}

Expand Down Expand Up @@ -379,6 +381,11 @@ public async Task DeleteMessageAsync(TaskAgentMessage message)
}
}

public async Task RefreshListenerTokenAsync(CancellationToken cancellationToken)
{
await _runnerServer.RefreshConnectionAsync(RunnerConnectionType.MessageQueue, TimeSpan.FromSeconds(60));
}

private TaskAgentMessage DecryptMessage(TaskAgentMessage message)
{
if (_session.EncryptionKey == null ||
Expand Down
4 changes: 4 additions & 0 deletions src/Runner.Listener/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@ await runServer.GetJobMessageAsync(messageRef.RunnerRequestId,
Trace.Info($"Service requests the hosted runner to shutdown. Reason: '{HostedRunnerShutdownMessage.Reason}'.");
return Constants.Runner.ReturnCode.Success;
}
else if (string.Equals(message.MessageType, TaskAgentMessageTypes.ForceTokenRefresh))
{
await _listener.RefreshListenerTokenAsync(messageQueueLoopTokenSource.Token);
}
else
{
Trace.Error($"Received message {message.MessageId} with unsupported message type {message.MessageType}.");
Expand Down
10 changes: 10 additions & 0 deletions src/Sdk/DTWebApi/WebApi/TaskAgentMessageTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Runtime.Serialization;

namespace GitHub.DistributedTask.WebApi
{
public sealed class TaskAgentMessageTypes
{
public static readonly string ForceTokenRefresh = "ForceTokenRefresh";
}
}
Loading