Changeset 9022 for trunk/sources/HeuristicLab.Services.Hive
- Timestamp:
- 12/11/12 15:07:54 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Services.Hive/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Services.Hive/3.3/HiveDao.cs
r7916 r9022 49 49 } 50 50 51 public IEnumerable<DT.LightweightTask> GetLightweightTasksForJob(Guid jobId) { 52 List<DT.LightweightTask> tasks = new List<DT.LightweightTask>(); 53 54 using (var db = CreateContext()) { 55 var tasksQuery = from task in db.Tasks 56 where task.JobId == jobId 57 select new { task.TaskId, task.ExecutionTimeMs, task.ParentTaskId, task.StateLogs, task.State, task.Command }; 58 59 var taskDatasQuery = from task in db.Tasks 60 where task.JobId == jobId && task.JobData != null 61 select new { task.TaskId, task.JobData.LastUpdate }; 62 63 foreach (var task in tasksQuery) { 64 DT.LightweightTask t = new DT.LightweightTask(); 65 t.Id = task.TaskId; 66 t.ExecutionTime = TimeSpan.FromMilliseconds(task.ExecutionTimeMs); 67 t.ParentTaskId = task.ParentTaskId; 68 t.StateLog = task.StateLogs == null ? new List<DT.StateLog>() : task.StateLogs.Select(x => DataTransfer.Convert.ToDto(x)).OrderBy(x => x.DateTime).ToList(); 69 t.State = DataTransfer.Convert.ToDto(task.State); 70 t.Command = DataTransfer.Convert.ToDto(task.Command); 71 t.LastTaskDataUpdate = taskDatasQuery.Where(x => x.TaskId == task.TaskId).Count() > 0 ? taskDatasQuery.Select(x => x.LastUpdate).First() : DateTime.MinValue; 72 tasks.Add(t); 73 } 74 } 75 return tasks; 76 } 77 78 public IEnumerable<DT.LightweightTask> GetLightweightTasks(Expression<Func<Task, bool>> predicate) { 79 List<DT.LightweightTask> tasks = new List<DT.LightweightTask>(); 80 81 using (var db = CreateContext()) { 82 var tasksQuery = db.Tasks.Where(predicate).Select(task => new { task.TaskId, task.ExecutionTimeMs, task.ParentTaskId, task.StateLogs, task.State, task.Command }); 83 var taskDatasQuery = db.Tasks.Where(predicate).Where(task => task.JobData != null).Select(task => new { task.TaskId, task.JobData.LastUpdate }); 84 85 foreach (var task in tasksQuery) { 86 DT.LightweightTask t = new DT.LightweightTask(); 87 t.Id = task.TaskId; 88 t.ExecutionTime = TimeSpan.FromMilliseconds(task.ExecutionTimeMs); 89 t.ParentTaskId = task.ParentTaskId; 90 t.StateLog = task.StateLogs == null ? new List<DT.StateLog>() : task.StateLogs.Select(x => DataTransfer.Convert.ToDto(x)).OrderBy(x => x.DateTime).ToList(); 91 t.State = DataTransfer.Convert.ToDto(task.State); 92 t.Command = DataTransfer.Convert.ToDto(task.Command); 93 t.LastTaskDataUpdate = taskDatasQuery.Where(x => x.TaskId == task.TaskId).Count() > 0 ? taskDatasQuery.Select(x => x.LastUpdate).First() : DateTime.MinValue; 94 tasks.Add(t); 95 } 96 } 97 return tasks; 98 } 99 51 100 public Guid AddTask(DT.Task dto) { 52 101 using (var db = CreateContext()) { … … 780 829 } 781 830 831 public Dictionary<Guid, int> GetWaitingTasksByUser() { 832 using (var db = CreateContext()) { 833 var waitingTasksByUser = from task in db.Tasks 834 where task.State == TaskState.Waiting 835 group task by task.Job.OwnerUserId into g 836 select new { UserId = g.Key, UsedCores = g.Count() }; 837 return waitingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores); 838 } 839 } 840 841 public Dictionary<Guid, int> GetCalculatingTasksByUser() { 842 using (var db = CreateContext()) { 843 var calculatingTasksByUser = from task in db.Tasks 844 where task.State == TaskState.Calculating 845 group task by task.Job.OwnerUserId into g 846 select new { UserId = g.Key, UsedCores = g.Count() }; 847 return calculatingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores); 848 } 849 } 850 782 851 public List<DT.UserStatistics> GetUserStatistics() { 783 852 using (var db = CreateContext()) { -
trunk/sources/HeuristicLab.Services.Hive/3.3/HiveService.cs
r8071 r9022 128 128 129 129 return trans.UseTransaction(() => { 130 return dao.Get Tasks(x => x.JobId == jobId).Select(x => new LightweightTask(x)).ToArray();130 return dao.GetLightweightTasksForJob(jobId).ToArray(); 131 131 }, false, false); 132 132 } -
trunk/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IHiveDao.cs
r7916 r9022 31 31 DT.Task GetTask(Guid id); 32 32 IEnumerable<DT.Task> GetTasks(Expression<Func<Task, bool>> predicate); 33 IEnumerable<DT.LightweightTask> GetLightweightTasksForJob(Guid jobId); 34 IEnumerable<DT.LightweightTask> GetLightweightTasks(Expression<Func<Task, bool>> predicate); 33 35 Guid AddTask(DT.Task dto); 34 36 void UpdateTask(DT.Task dto); … … 145 147 146 148 #region Statistics Methods 149 Dictionary<Guid, int> GetWaitingTasksByUser(); 150 Dictionary<Guid, int> GetCalculatingTasksByUser(); 147 151 DT.Statistics GetStatistic(Guid id); 148 152 IEnumerable<DT.Statistics> GetStatistics(Expression<Func<Statistics, bool>> predicate);
Note: See TracChangeset
for help on using the changeset viewer.