/// <summary> /// Rebuilds the CohortCompiler diagram which shows all the currently configured tasks /// </summary> /// <param name="cancelTasks"></param> private void RecreateAllTasks(bool cancelTasks = true) { if (cancelTasks) { Compiler.CancelAllTasks(false); } tlvConfiguration.ClearObjects(); tlvConfiguration.Enabled = true; _cic.CreateRootContainerIfNotExists(); //if there is no root container,create one _root = _cic.RootCohortAggregateContainer; _globals = _cic.GetAllParameters(); //Could have configured/unconfigured a joinable state foreach (var j in Compiler.Tasks.Keys.OfType <JoinableTask>()) { j.RefreshIsUsedState(); } try { tlvConfiguration.AddObject(new CohortIdentificationHeader()); tlvConfiguration.AddObject(new JoinableCollectionNode(_cic, _cic.GetAllJoinables())); tlvConfiguration.ExpandAll(); } catch (Exception e) { tlvConfiguration.Enabled = false; ExceptionViewer.Show("Failed to populate tree of Tasks", e); } }
public ICompileable Run(CancellationToken token) { try { var globals = _cic.GetAllParameters(); //clear compiler list Compiler.CancelAllTasks(true); SetPhase(Phase.RunningJoinableTasks); Parallel.ForEach(_cic.GetAllJoinables(), (j) => Compiler.AddTask(j, globals)); Compiler.CancelAllTasks(false); RunAsync(Compiler.Tasks.Keys.Where(c => c is JoinableTask && c.State == CompilationState.NotScheduled), token); SetPhase(Phase.CachingJoinableTasks); CacheAsync(Compiler.Tasks.Keys.OfType <JoinableTask>().Where(c => c.State == CompilationState.Finished && c.IsCacheableWhenFinished()), token); SetPhase(Phase.RunningAggregateTasks); // Add all aggregates Parallel.ForEach(_cic.RootCohortAggregateContainer.GetAllAggregateConfigurationsRecursively(), (c) => Compiler.AddTask(c, globals)); Compiler.CancelAllTasks(false); RunAsync(Compiler.Tasks.Keys.Where(c => c is AggregationTask && c.IsEnabled() && c.State == CompilationState.NotScheduled), token); SetPhase(Phase.CachingAggregateTasks); CacheAsync(Compiler.Tasks.Keys.OfType <AggregationTask>().Where(c => c.State == CompilationState.Finished && c.IsCacheableWhenFinished()), token); SetPhase(Phase.RunningFinalTotals); var toReturn = Compiler.AddTask(_cic.RootCohortAggregateContainer, globals); if (RunSubcontainers) { Parallel.ForEach( _cic.RootCohortAggregateContainer.GetAllSubContainersRecursively().Where(c => !c.IsDisabled), (a) => Compiler.AddTask(a, globals)); } Compiler.CancelAllTasks(false); RunAsync(Compiler.Tasks.Keys.Where(c => c.State == CompilationState.NotScheduled && c.IsEnabled()), token); SetPhase(Phase.Finished); return(toReturn); } catch (OperationCanceledException) { SetPhase(Phase.None); return(null); } }
/// <summary> /// Adds all subqueries and containers that are below the current CohortIdentificationConfiguration as tasks to the compiler /// </summary> /// <param name="addSubcontainerTasks">The root container is always added to the task list but you could skip subcontainer totals if all you care about is the final total for the cohort /// and you don't have a dependant UI etc. Passing false will add all joinables, subqueries etc and the root container (final answer for who is in cohort) only.</param> /// <returns></returns> public List <ICompileable> AddAllTasks(bool addSubcontainerTasks = true) { var toReturn = new List <ICompileable>(); var globals = CohortIdentificationConfiguration.GetAllParameters(); CohortIdentificationConfiguration.CreateRootContainerIfNotExists(); foreach (var joinable in CohortIdentificationConfiguration.GetAllJoinables()) { toReturn.Add(AddTask(joinable, globals)); } toReturn.AddRange(AddTasksRecursively(globals, CohortIdentificationConfiguration.RootCohortAggregateContainer, addSubcontainerTasks)); return(toReturn); }
/// <summary> /// Rebuilds the CohortCompiler diagram which shows all the currently configured tasks /// </summary> /// <param name="cancelTasks"></param> private void RecreateAllTasks(bool cancelTasks = true) { if (cancelTasks) { Compiler.CancelAllTasks(false); } _configuration.CreateRootContainerIfNotExists(); //if there is no root container,create one _root = _configuration.RootCohortAggregateContainer; _globals = _configuration.GetAllParameters(); //Could have configured/unconfigured a joinable state foreach (var j in Compiler.Tasks.Keys.OfType <JoinableTask>()) { j.RefreshIsUsedState(); } }
public CohortQueryBuilder(CohortIdentificationConfiguration configuration, ICoreChildProvider childProvider) : this(configuration.GetAllParameters(), childProvider) { if (configuration == null) { throw new QueryBuildingException("Configuration has not been set yet"); } if (configuration.RootCohortAggregateContainer_ID == null) { throw new QueryBuildingException("Root container not set on CohortIdentificationConfiguration " + configuration); } if (configuration.QueryCachingServer_ID != null) { CacheServer = configuration.QueryCachingServer; } //set ourselves up to run with the root container container = configuration.RootCohortAggregateContainer; SetChildProviderIfNull(); }
private ICompileable RunRootContainerOnlyNoCaching(CohortCompiler cohortCompiler) { //add root container task var task = cohortCompiler.AddTask(_cohortIdentificationConfiguration.RootCohortAggregateContainer, _cohortIdentificationConfiguration.GetAllParameters()); cohortCompiler.LaunchSingleTask(task, Timeout, false); //timeout is in seconds int countDown = Math.Max(5000, Timeout * 1000); while ( //hasn't timed out countDown > 0 && ( //state isn't a final state task.State == CompilationState.Executing || task.State == CompilationState.NotScheduled || task.State == CompilationState.Scheduled) ) { Task.Delay(100).Wait(); countDown -= 100; } if (countDown <= 0) { try { throw new Exception("Cohort failed to reach a final state (Finished/Crashed) after " + Timeout + " seconds. Current state is " + task.State + ". The task will be cancelled"); } finally { cohortCompiler.CancelAllTasks(true); } } return(task); }