public async Task Run() { var t1 = new TaskConfigTreeNode(new TaskConfig("T1", 2, new List <string> { "C1", "C2", "C3" }, null, false)); var t2 = new TaskConfigTreeNode(new TaskConfig("T2", 2, new List <string> { "C1", "C2", "C3" }, "T1", false)); var t3 = new TaskConfigTreeNode(new TaskConfig("T3", 2, new List <string> { "C1", "C2", "C4" }, "T1", true)); var t4 = new TaskConfigTreeNode(new TaskConfig("T4", 2, new List <string> { "C2", "C4", "C5" }, "T2", false)); t1 .AddChildNode(t2) .AddChildNode(t3); t2.AddChildNode(t4); var tree = new TaskConfigTree(t1); var taskList = tree.CreateRuntimeTasks(); var taskExecutor = new TaskExecutor(); await taskExecutor.Execute(taskList); }
private void CreateRuntimeTasks(TaskConfigTreeNode node, List <RuntimeTask> accumulator, List <RuntimeTask> parentTasks) { //var tasksDictionary = new Dictionary<string, List<RuntimeTask>>(); //key is TaskConfigName var tasks = CreateRuntimeTaskForNode(node, parentTasks); accumulator.AddRange(tasks); foreach (var dependency in node.Children) { CreateRuntimeTasks(dependency, accumulator, tasks); } }
private List <RuntimeTask> CreateRuntimeTaskForNode(TaskConfigTreeNode node, List <RuntimeTask> parentTasks) { var result = new List <RuntimeTask>(); foreach (var taskConfigConnection in node.TaskConfig.Connections) { var task = new Task(() => { Console.WriteLine($"{DateTime.Now}: Executing task {node.TaskConfig.Name} and connection {taskConfigConnection}."); Thread.Sleep(1000); }); var runtimeTask = new RuntimeTask(task, taskConfigConnection, node.TaskConfig.Name, node.TaskConfig.MaxDegreeOfParallelism); if (parentTasks != null) { if (node.TaskConfig.OnlyIfDependentTaskSucceeded) { runtimeTask.Dependencies.AddRange(parentTasks.Select(rt => rt.Task)); } else { var parentRuntimeTaskWithSameConnection = parentTasks.SingleOrDefault(rt => rt.Connection == taskConfigConnection); if (parentRuntimeTaskWithSameConnection != null) { runtimeTask.Dependencies.Add(parentRuntimeTaskWithSameConnection.Task); } else { //TBD } } } result.Add(runtimeTask); } return(result); }
public TaskConfigTree(TaskConfigTreeNode root) { Root = root; }
public TaskConfigTreeNode AddChildNode(TaskConfigTreeNode child) { _children.Add(child); return(this); }