Changeset 9123 for trunk/sources/HeuristicLab.Services.Hive/3.3/Scheduler
- Timestamp:
- 01/07/13 22:00:04 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Services.Hive
- Files:
-
- 2 added
- 2 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Services.Hive
-
Property
svn:mergeinfo
set to
/branches/HiveTaskScheduler/HeuristicLab.Services.Hive merged eligible
-
Property
svn:mergeinfo
set to
-
trunk/sources/HeuristicLab.Services.Hive/3.3/Scheduler/RoundRobinTaskScheduler.cs
r8998 r9123 31 31 } 32 32 33 public IEnumerable<Task > Schedule(IEnumerable<Task> tasks, int count = 1) {34 if (!tasks.Any()) return Enumerable.Empty<Task >();33 public IEnumerable<TaskInfoForScheduler> Schedule(IEnumerable<TaskInfoForScheduler> tasks, int count = 1) { 34 if (!tasks.Any()) return Enumerable.Empty<TaskInfoForScheduler>(); 35 35 36 36 var userPriorities = dao.GetUserPriorities(x => true).OrderBy(x => x.DateEnqueued).ToArray(); 37 37 38 var jobs = new List<Job >();38 var jobs = new List<JobInfoForScheduler>(); 39 39 foreach (var userPriority in userPriorities) { 40 jobs.AddRange(dao.GetJob s(x => x.OwnerUserId == userPriority.Id));40 jobs.AddRange(dao.GetJobInfoForScheduler(x => x.OwnerUserId == userPriority.Id)); 41 41 } 42 42 … … 44 44 task => task.JobId, 45 45 job => job.Id, 46 (task, job) => new { Task = task, Job = job })46 (task, job) => new { Task = task, JobInfo = job }) 47 47 .OrderByDescending(x => x.Task.Priority) 48 48 .ToList(); 49 49 50 var scheduledTasks = new List<Task >();50 var scheduledTasks = new List<TaskInfoForScheduler>(); 51 51 int priorityIndex = 0; 52 52 … … 55 55 for (int i = 0; i < count; i++) { 56 56 var defaultEntry = taskJobRelations.First(); // search first task which is not included yet 57 var priorityEntries = taskJobRelations.Where(x => x.Job.OwnerUserId == userPriorities[priorityIndex].Id).ToArray(); // search for tasks with desired user priority 58 while (!priorityEntries.Any() && ++priorityIndex < userPriorities.Length) 59 priorityEntries = taskJobRelations.Where(x => x.Job.OwnerUserId == userPriorities[priorityIndex].Id).ToArray(); 57 var priorityEntries = taskJobRelations.Where(x => x.JobInfo.OwnerUserId == userPriorities[priorityIndex].Id).ToArray(); // search for tasks with desired user priority 58 while (!priorityEntries.Any() && priorityIndex < userPriorities.Length - 1) { 59 priorityIndex++; 60 priorityEntries = taskJobRelations.Where(x => x.JobInfo.OwnerUserId == userPriorities[priorityIndex].Id).ToArray(); 61 } 60 62 if (priorityEntries.Any()) { // tasks with desired user priority found 61 var priorityEntry = priorityEntries.OrderByDescending(x => x.Task.Priority).ThenBy(x => x.Job .DateCreated).First();63 var priorityEntry = priorityEntries.OrderByDescending(x => x.Task.Priority).ThenBy(x => x.JobInfo.DateCreated).First(); 62 64 if (defaultEntry.Task.Priority <= priorityEntry.Task.Priority) { 63 65 taskJobRelations.Remove(priorityEntry); 64 66 scheduledTasks.Add(priorityEntry.Task); 67 UpdateUserPriority(userPriorities[priorityIndex]); 65 68 priorityIndex++; 66 69 } else { // there are other tasks with higher priorities … … 72 75 scheduledTasks.Add(defaultEntry.Task); 73 76 } 77 78 if (priorityIndex >= (userPriorities.Length - 1)) priorityIndex = 0; 74 79 } 75 76 // requeue user priorities77 if (priorityIndex < userPriorities.Length)78 for (int i = 0; i < priorityIndex; i++) {79 userPriorities[i].DateEnqueued = DateTime.Now;80 dao.EnqueueUserPriority(userPriorities[i]);81 }82 80 83 81 return scheduledTasks; 84 82 } 83 84 private void UpdateUserPriority(UserPriority up) { 85 up.DateEnqueued = DateTime.Now; 86 dao.EnqueueUserPriority(up); 87 } 85 88 } 86 89 }
Note: See TracChangeset
for help on using the changeset viewer.