Skip to content

Commit

Permalink
Handle ForceTokenRefresh message (#3133)
Browse files Browse the repository at this point in the history
* Handle ForceTokenRefresh message

* move to constants

* format
  • Loading branch information
luketomlinson authored Feb 7, 2024
1 parent bcc665a commit 651ea42
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
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";
}
}

0 comments on commit 651ea42

Please sign in to comment.