-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Acknowledge runner request #3996
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 |
|---|---|---|
|
|
@@ -70,7 +70,7 @@ protected async Task<VssConnection> EstablishVssConnection(Uri serverUrl, VssCre | |
|
|
||
| protected async Task RetryRequest(Func<Task> func, | ||
| CancellationToken cancellationToken, | ||
| int maxRetryAttemptsCount = 5, | ||
| int maxAttempts = 5, | ||
|
Collaborator
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. The previous description was a misnomer. This value indicates maximum number of attempts (i.e. initial attempt + retries). |
||
| Func<Exception, bool> shouldRetry = null | ||
| ) | ||
| { | ||
|
|
@@ -79,31 +79,31 @@ async Task<Unit> wrappedFunc() | |
| await func(); | ||
| return Unit.Value; | ||
| } | ||
| await RetryRequest<Unit>(wrappedFunc, cancellationToken, maxRetryAttemptsCount, shouldRetry); | ||
| await RetryRequest<Unit>(wrappedFunc, cancellationToken, maxAttempts, shouldRetry); | ||
| } | ||
|
|
||
| protected async Task<T> RetryRequest<T>(Func<Task<T>> func, | ||
| CancellationToken cancellationToken, | ||
| int maxRetryAttemptsCount = 5, | ||
| int maxAttempts = 5, | ||
| Func<Exception, bool> shouldRetry = null | ||
| ) | ||
| { | ||
| var retryCount = 0; | ||
| var attempt = 0; | ||
| while (true) | ||
| { | ||
| retryCount++; | ||
| attempt++; | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
| try | ||
| { | ||
| return await func(); | ||
| } | ||
| // TODO: Add handling of non-retriable exceptions: https://github.com/github/actions-broker/issues/122 | ||
| catch (Exception ex) when (retryCount < maxRetryAttemptsCount && (shouldRetry == null || shouldRetry(ex))) | ||
| catch (Exception ex) when (attempt < maxAttempts && (shouldRetry == null || shouldRetry(ex))) | ||
| { | ||
| Trace.Error("Catch exception during request"); | ||
| Trace.Error(ex); | ||
| var backOff = BackoffTimerHelper.GetRandomBackoff(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(15)); | ||
| Trace.Warning($"Back off {backOff.TotalSeconds} seconds before next retry. {maxRetryAttemptsCount - retryCount} attempt left."); | ||
| Trace.Warning($"Back off {backOff.TotalSeconds} seconds before next retry. {maxAttempts - attempt} attempt left."); | ||
| await Task.Delay(backOff, cancellationToken); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ public sealed class BrokerMessageListener : RunnerService, IMessageListener | |
| private RunnerSettings _settings; | ||
| private ITerminal _term; | ||
| private TimeSpan _getNextMessageRetryInterval; | ||
| private TaskAgentStatus runnerStatus = TaskAgentStatus.Online; | ||
| private TaskAgentStatus _runnerStatus = TaskAgentStatus.Online; | ||
|
Collaborator
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. Fixed |
||
| private CancellationTokenSource _getMessagesTokenSource; | ||
| private VssCredentials _creds; | ||
| private VssCredentials _credsV2; | ||
|
|
@@ -258,7 +258,7 @@ public async Task DeleteSessionAsync() | |
| public void OnJobStatus(object sender, JobStatusEventArgs e) | ||
| { | ||
| Trace.Info("Received job status event. JobState: {0}", e.Status); | ||
| runnerStatus = e.Status; | ||
| _runnerStatus = e.Status; | ||
| try | ||
| { | ||
| _getMessagesTokenSource?.Cancel(); | ||
|
|
@@ -291,7 +291,7 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token) | |
| } | ||
|
|
||
| message = await _brokerServer.GetRunnerMessageAsync(_session.SessionId, | ||
| runnerStatus, | ||
| _runnerStatus, | ||
| BuildConstants.RunnerPackage.Version, | ||
| VarUtil.OS, | ||
| VarUtil.OSArchitecture, | ||
|
|
@@ -417,6 +417,21 @@ public async Task DeleteMessageAsync(TaskAgentMessage message) | |
| await Task.CompletedTask; | ||
| } | ||
|
|
||
| public async Task AcknowledgeMessageAsync(string runnerRequestId, CancellationToken cancellationToken) | ||
| { | ||
| using var timeoutCts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); // Short timeout | ||
| using var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutCts.Token); | ||
|
Contributor
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. 5 sec is meant to be short timeout in long run as well? do we do such things at any place in code?
Collaborator
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. We can refine this further if needed. I just wanted to keep it short so it doesn't interfere with actually acquiring the job. This new message ACK is best-effort anyway. It doesn't have to be 100%, it just has to be good enough to help us distinguish acquire timeout reason for the most part. |
||
| Trace.Info($"Acknowledging runner request '{runnerRequestId}'."); | ||
| await _brokerServer.AcknowledgeRunnerRequestAsync( | ||
| runnerRequestId, | ||
| _session.SessionId, | ||
| _runnerStatus, | ||
| BuildConstants.RunnerPackage.Version, | ||
ericsciple marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| VarUtil.OS, | ||
| VarUtil.OSArchitecture, | ||
| linkedCts.Token); | ||
| } | ||
|
|
||
| private bool IsGetNextMessageExceptionRetriable(Exception ex) | ||
| { | ||
| if (ex is TaskAgentNotFoundException || | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.