public void Cancel(StagePath path) { try { if (path == StagePath.Root) { _cancellationSource.Cancel(); } foreach (var pathToCancel in GetPathAndDescendantsOf(path)) { if (Stages.TryGetValue(pathToCancel, out IModule stage)) { stage.Cancel(); } else { throw new Exception($"Unable to find stage to cancel {pathToCancel}"); } } } catch (Exception ex) { Logger?.Write(LogLevels.Error, "Error during cancellation"); Logger?.Write(LogLevels.Error, ex); } }
public RunInfo(RunType type, TId jobId, TId requestId, StagePath path) { Type = type; JobId = jobId; RequestId = requestId; Path = new StagePath(path); }
private IModule GetStage(StagePath path) { if (!Stages.TryGetValue(path, out IModule stage)) { throw new Exception($"Unable to find stage {path}"); } return(stage); }
public IStageBuilder Add <TChildModule>(Action <StageBuilder <TChildModule> > builderDelegate) where TChildModule : IModule { var builder = new StageBuilder <TChildModule>(DataLayer, RunInfo, StagePath.CreateChild(++ChildIndex)); builderDelegate.Invoke(builder); Builders.Add(builder); return(this); }
private async Task RunStage(StagePath path, IModule stage) { try { await stage.Run(); await InvokeCreateChildren(stage); await RunChildren(path, stage); } catch (OperationCanceledException) { Logger?.Write(LogLevels.Warning, path, $"Stage {stage} was cancelled"); } catch (Exception ex) { Logger?.Write(LogLevels.Error, path, $"Stage {stage} faulted: {ex}"); } }
private async Task RunChildren(StagePath path, IModule stage) { List <Task> tasks = new List <Task>(); if (!stage.IsEnabled) { return; } foreach (var childPath in GetChildPaths(path)) { var child = GetStage(childPath); tasks.Add(RunStage(childPath, child)); if (stage.MaxParallelChildren > 0 && tasks.Count == stage.MaxParallelChildren) { tasks.Remove(await Task.WhenAny(tasks.ToArray())); } } await Task.WhenAll(tasks.ToArray()); }
private StagePath[] GetChildPaths(StagePath path) => Stages.Where(x => path.IsParentOf(x.Key)).Select(x => x.Key).OrderBy(x => x).ToArray();
private StagePath[] GetPathAndDescendantsOf(StagePath path) => Stages.Where(x => x.Key == path || x.Key.IsDescendantOf(path)).Select(x => x.Key).OrderBy(x => x).ToArray();
public StageBuilder(IDataLayer dataLayer, IRunInfo runInfo, StagePath stagePath) { DataLayer = dataLayer; RunInfo = runInfo; StagePath = stagePath; }