コード例 #1
0
        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);
            }
        }
コード例 #2
0
 public RunInfo(RunType type, TId jobId, TId requestId, StagePath path)
 {
     Type      = type;
     JobId     = jobId;
     RequestId = requestId;
     Path      = new StagePath(path);
 }
コード例 #3
0
 private IModule GetStage(StagePath path)
 {
     if (!Stages.TryGetValue(path, out IModule stage))
     {
         throw new Exception($"Unable to find stage {path}");
     }
     return(stage);
 }
コード例 #4
0
        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);
        }
コード例 #5
0
 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}");
     }
 }
コード例 #6
0
        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());
        }
コード例 #7
0
 private StagePath[] GetChildPaths(StagePath path) =>
 Stages.Where(x => path.IsParentOf(x.Key)).Select(x => x.Key).OrderBy(x => x).ToArray();
コード例 #8
0
 private StagePath[] GetPathAndDescendantsOf(StagePath path) =>
 Stages.Where(x => x.Key == path || x.Key.IsDescendantOf(path)).Select(x => x.Key).OrderBy(x => x).ToArray();
コード例 #9
0
 public StageBuilder(IDataLayer dataLayer, IRunInfo runInfo, StagePath stagePath)
 {
     DataLayer = dataLayer;
     RunInfo   = runInfo;
     StagePath = stagePath;
 }