Changeset 16311 for branches/2845_EnhancedProgress/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDao.cs
- Timestamp:
- 11/20/18 15:26:57 (6 years ago)
- Location:
- branches/2845_EnhancedProgress
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2845_EnhancedProgress
- Property svn:mergeinfo changed
-
branches/2845_EnhancedProgress/HeuristicLab.Services.Hive.DataAccess
- Property svn:mergeinfo changed
-
branches/2845_EnhancedProgress/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDao.cs
r16308 r16311 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 27 27 namespace HeuristicLab.Services.Hive.DataAccess.Daos { 28 28 public class TaskDao : GenericDao<Guid, Task> { 29 private Table<AssignedResource> AssignedResourceTable {30 get { return DataContext.GetTable<AssignedResource>(); }31 }32 33 29 public TaskDao(DataContext dataContext) : base(dataContext) { } 34 30 … … 54 50 //Because there is at the moment no case where this makes sense (there don't exist parent tasks which need to be calculated), 55 51 //we skip this step because it's wasted runtime 56 return DataContext.ExecuteQuery<TaskPriorityInfo>(GetWaitingTasksQueryString, slave.ResourceId, Enum.GetName(typeof(TaskState), TaskState.Waiting), slave.FreeCores, slave.FreeMemory).ToList(); 52 return DataContext.ExecuteQuery<TaskPriorityInfo>(GetWaitingTasksQueryString, 53 slave.ResourceId, 54 Enum.GetName(typeof(TaskState), TaskState.Waiting), 55 slave.FreeCores, 56 slave.FreeMemory).ToList(); 57 57 } 58 58 … … 62 62 /// <param name="resourceIds">list of resourceids which for which the task should be valid</param> 63 63 /// <param name="count">maximum number of task to return</param> 64 /// <param name="finished">if true, all parent task which have FinishWhenChildJobsFinished=true are returned, otherwise only FinishWhenChildJobsFinished=false are returned</param>64 /// <param name="finished">if true, all parent tasks which have FinishWhenChildJobsFinished=true are returned, otherwise only FinishWhenChildJobsFinished=false are returned</param> 65 65 /// <returns></returns> 66 66 public IEnumerable<Task> GetParentTasks(IEnumerable<Guid> resourceIds, int count, bool finished) { 67 var query = from ar in AssignedResourceTable 68 where resourceIds.Contains(ar.ResourceId) 69 && ar.Task.State == TaskState.Waiting 70 && ar.Task.IsParentTask 71 && (finished ? ar.Task.FinishWhenChildJobsFinished : !ar.Task.FinishWhenChildJobsFinished) 72 && (from child in Table 73 where child.ParentTaskId == ar.Task.TaskId 74 select child.State == TaskState.Finished 75 || child.State == TaskState.Aborted 76 || child.State == TaskState.Failed).All(x => x) 77 && (from child in Table // avoid returning WaitForChildTasks task where no child-task exist (yet) 78 where child.ParentTaskId == ar.Task.TaskId 79 select child).Any() 80 orderby ar.Task.Priority descending 81 select ar.Task; 67 var query = from t in Table 68 where t.State == TaskState.Waiting 69 && t.IsParentTask 70 && t.Job.AssignedJobResources.All(x => resourceIds.ToList().Contains(x.ResourceId)) 71 && t.FinishWhenChildJobsFinished == finished 72 && t.ChildJobs.Any() 73 && t.ChildJobs.All(x => 74 x.State == TaskState.Finished 75 || x.State == TaskState.Aborted 76 || x.State == TaskState.Failed) 77 orderby t.Priority descending 78 select t; 82 79 return count == 0 ? query.ToArray() : query.Take(count).ToArray(); 83 80 } … … 96 93 97 94 #region String queries 95 private const string GetCalculatingChildTasksByProjectId = @" 96 SELECT t.* FROM [Task] t, [Job] j 97 WHERE t.IsParentTask = 0 98 AND t.TaskState = 'Calculating' 99 AND t.JobId = j.JobId 100 AND j.ProjectId = {0} 101 ORDER BY j.ProjectId 102 "; 98 103 private const string GetWaitingTasksQueryString = @" 99 WITH prAS (104 WITH rbranch AS ( 100 105 SELECT ResourceId, ParentResourceId 101 106 FROM [Resource] … … 103 108 UNION ALL 104 109 SELECT r.ResourceId, r.ParentResourceId 105 FROM [Resource] r JOIN pr ON r.ResourceId = pr.ParentResourceId 110 FROM [Resource] r 111 JOIN rbranch rb ON rb.ParentResourceId = r.ResourceId 106 112 ) 107 113 SELECT DISTINCT t.TaskId, t.JobId, t.Priority 108 FROM pr JOIN AssignedResources ar ON ar.ResourceId = pr.ResourceId 109 JOIN Task t ON t.TaskId = ar.TaskId 114 FROM [Task] t, [Job] j, [AssignedJobResource] ajr, rbranch 110 115 WHERE NOT (t.IsParentTask = 1 AND t.FinishWhenChildJobsFinished = 1) 111 AND t.TaskState = {1} 112 AND t.CoresNeeded <= {2} 113 AND t.MemoryNeeded <= {3} 116 AND t.TaskState = {1} 117 AND t.CoresNeeded <= {2} 118 AND t.MemoryNeeded <= {3} 119 AND t.JobId = j.JobId 120 AND j.JobState = 'Online' 121 AND j.JobId = ajr.JobId 122 AND ajr.ResourceId = rbranch.ResourceId 114 123 "; 115 124
Note: See TracChangeset
for help on using the changeset viewer.