Changeset 12691 for branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDao.cs
- Timestamp:
- 07/08/15 15:51:32 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Daos/TaskDao.cs
r12584 r12691 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Data.Linq; 24 25 using System.Linq; … … 29 30 30 31 public override Task GetById(Guid id) { 31 return Table.SingleOrDefault(x => x.TaskId ==id);32 return GetByIdQuery(DataContext, id); 32 33 } 33 34 … … 39 40 return Table.Where(x => x.JobId == id); 40 41 } 42 public class TaskPriorityInfo { 43 public Guid JobId { get; set; } 44 public Guid TaskId { get; set; } 45 public int Priority { get; set; } 46 } 47 48 public IEnumerable<TaskPriorityInfo> GetWaitingTasks(Slave slave) { 49 //Originally we checked here if there are parent tasks which should be calculated (with GetParentTasks(resourceIds, count, false);). 50 //Because there is at the moment no case where this makes sense (there don't exist parent tasks which need to be calculated), 51 //we skip this step because it's wasted runtime 52 return DataContext.ExecuteQuery<TaskPriorityInfo>(GetWaitingTasksQueryString, slave.ResourceId, Enum.GetName(typeof(TaskState), TaskState.Waiting), slave.FreeCores, slave.FreeMemory).ToList(); 53 } 54 55 public void UpdateExecutionTime(Guid taskId, double executionTime) { 56 DataContext.ExecuteCommand(UpdateExecutionTimeQuery, executionTime, DateTime.Now, taskId); 57 } 58 59 #region Compiled queries 60 private static readonly Func<DataContext, Guid, Task> GetByIdQuery = 61 CompiledQuery.Compile((DataContext db, Guid taskId) => 62 (from task in db.GetTable<Task>() 63 where task.TaskId == taskId 64 select task).SingleOrDefault()); 65 #endregion 66 67 #region String queries 68 private const string GetWaitingTasksQueryString = @" 69 WITH pr AS ( 70 SELECT ResourceId, ParentResourceId 71 FROM [Resource] 72 WHERE ResourceId = {0} 73 UNION ALL 74 SELECT r.ResourceId, r.ParentResourceId 75 FROM [Resource] r JOIN pr ON r.ResourceId = pr.ParentResourceId 76 ) 77 SELECT DISTINCT t.TaskId, t.JobId, t.Priority 78 FROM pr JOIN AssignedResources ar ON ar.ResourceId = pr.ResourceId 79 JOIN Task t ON t.TaskId = ar.TaskId 80 WHERE NOT (t.IsParentTask = 1 AND t.FinishWhenChildJobsFinished = 1) 81 AND t.TaskState = {1} 82 AND t.CoresNeeded <= {2} 83 AND t.MemoryNeeded <= {3} 84 "; 85 86 private const string UpdateExecutionTimeQuery = @" 87 UPDATE [Task] 88 SET ExecutionTimeMs = {0}, 89 LastHeartbeat = {1} 90 WHERE TaskId = {2} 91 "; 92 #endregion 41 93 } 42 94 }
Note: See TracChangeset
for help on using the changeset viewer.