Skip to content

Commit 00e60ca

Browse files
authored
Pass timeout in executioncontext instead of stepsrunner (#2714) (#2715)
* Pass timeout in executioncontext instead of stepsrunner * Fix linting
1 parent f8ad46b commit 00e60ca

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/Runner.Worker/ExecutionContext.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public interface IExecutionContext : IRunnerService
8383
// Initialize
8484
void InitializeJob(Pipelines.AgentJobRequestMessage message, CancellationToken token);
8585
void CancelToken();
86-
IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, ActionRunStage stage, Dictionary<string, string> intraActionState = null, int? recordOrder = null, IPagingLogger logger = null, bool isEmbedded = false, CancellationTokenSource cancellationTokenSource = null, Guid embeddedId = default(Guid), string siblingScopeName = null);
86+
IExecutionContext CreateChild(Guid recordId, string displayName, string refName, string scopeName, string contextName, ActionRunStage stage, Dictionary<string, string> intraActionState = null, int? recordOrder = null, IPagingLogger logger = null, bool isEmbedded = false, CancellationTokenSource cancellationTokenSource = null, Guid embeddedId = default(Guid), string siblingScopeName = null, TimeSpan? timeout = null);
8787
IExecutionContext CreateEmbeddedChild(string scopeName, string contextName, Guid embeddedId, ActionRunStage stage, Dictionary<string, string> intraActionState = null, string siblingScopeName = null);
8888

8989
// logging
@@ -357,7 +357,8 @@ public IExecutionContext CreateChild(
357357
bool isEmbedded = false,
358358
CancellationTokenSource cancellationTokenSource = null,
359359
Guid embeddedId = default(Guid),
360-
string siblingScopeName = null)
360+
string siblingScopeName = null,
361+
TimeSpan? timeout = null)
361362
{
362363
Trace.Entering();
363364

@@ -386,6 +387,12 @@ public IExecutionContext CreateChild(
386387
child.ExpressionFunctions.Add(item);
387388
}
388389
child._cancellationTokenSource = cancellationTokenSource ?? new CancellationTokenSource();
390+
if (timeout != null)
391+
{
392+
// composite steps inherit the timeout from the parent, set by https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepstimeout-minutes
393+
child.SetTimeout(timeout);
394+
}
395+
389396
child.EchoOnActionCommand = EchoOnActionCommand;
390397

391398
if (recordOrder != null)
@@ -425,7 +432,7 @@ public IExecutionContext CreateEmbeddedChild(
425432
Dictionary<string, string> intraActionState = null,
426433
string siblingScopeName = null)
427434
{
428-
return Root.CreateChild(_record.Id, _record.Name, _record.Id.ToString("N"), scopeName, contextName, stage, logger: _logger, isEmbedded: true, cancellationTokenSource: null, intraActionState: intraActionState, embeddedId: embeddedId, siblingScopeName: siblingScopeName);
435+
return Root.CreateChild(_record.Id, _record.Name, _record.Id.ToString("N"), scopeName, contextName, stage, logger: _logger, isEmbedded: true, cancellationTokenSource: null, intraActionState: intraActionState, embeddedId: embeddedId, siblingScopeName: siblingScopeName, timeout: GetRemainingTimeout());
429436
}
430437

431438
public void Start(string currentOperation = null)

src/Runner.Worker/Handlers/CompositeActionHandler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,6 @@ private async Task RunStepAsync(IStep step)
421421
{
422422
Trace.Info($"Starting: {step.DisplayName}");
423423
step.ExecutionContext.Debug($"Starting: {step.DisplayName}");
424-
// composite steps inherit the timeout from the parent, set by https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepstimeout-minutes
425-
step.ExecutionContext.SetTimeout(step.ExecutionContext.Parent.GetRemainingTimeout());
426424

427425
await Common.Util.EncodingUtil.SetEncoding(HostContext, Trace, step.ExecutionContext.CancellationToken);
428426

0 commit comments

Comments
 (0)