Changeset 15644 for branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs
- Timestamp:
- 01/23/18 16:04:24 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveProjectManagement/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs
r15641 r15644 212 212 return actions; 213 213 } 214 215 /// <summary>216 /// Update the progress of each task217 /// Checks if all the task sent by heartbeat are supposed to be calculated by this slave218 /// </summary>219 private IEnumerable<MessageContainer> UpdateTasks_Old(IPersistenceManager pm, Heartbeat heartbeat, bool isAllowedToCalculate) {220 var taskDao = pm.TaskDao;221 var assignedResourceDao = pm.AssignedTaskResourceDao;222 var actions = new List<MessageContainer>();223 if (heartbeat.JobProgress == null || !heartbeat.JobProgress.Any())224 return actions;225 226 if (!isAllowedToCalculate && heartbeat.JobProgress.Count != 0) {227 actions.Add(new MessageContainer(MessageContainer.MessageType.PauseAll));228 } else {229 // select all tasks and statelogs with one query230 var taskIds = heartbeat.JobProgress.Select(x => x.Key).ToList();231 var taskInfos = pm.UseTransaction(() =>232 (from task in taskDao.GetAll()233 where taskIds.Contains(task.TaskId)234 let lastStateLog = task.StateLogs.OrderByDescending(x => x.DateTime).FirstOrDefault()235 select new {236 TaskId = task.TaskId,237 Command = task.Command,238 SlaveId = lastStateLog != null ? lastStateLog.SlaveId : default(Guid)239 }).ToList()240 );241 242 // process the jobProgresses243 foreach (var jobProgress in heartbeat.JobProgress) {244 var progress = jobProgress;245 var curTask = taskInfos.SingleOrDefault(x => x.TaskId == progress.Key);246 if (curTask == null) {247 actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, progress.Key));248 LogFactory.GetLogger(this.GetType().Namespace).Log("Task on slave " + heartbeat.SlaveId + " does not exist in DB: " + jobProgress.Key);249 } else {250 var slaveId = curTask.SlaveId;251 if (slaveId == Guid.Empty || slaveId != heartbeat.SlaveId) {252 // assigned slave does not match heartbeat253 actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, curTask.TaskId));254 LogFactory.GetLogger(this.GetType().Namespace).Log("The slave " + heartbeat.SlaveId + " is not supposed to calculate task: " + curTask.TaskId);255 } else if (!assignedResourceDao.TaskIsAllowedToBeCalculatedBySlave(curTask.TaskId, heartbeat.SlaveId)) {256 // assigned resources ids of task do not match with slaveId (and parent resourceGroupIds); this might happen when slave is moved to different group257 actions.Add(new MessageContainer(MessageContainer.MessageType.PauseTask, curTask.TaskId));258 } else {259 // update task execution time260 pm.UseTransaction(() => {261 taskDao.UpdateExecutionTime(curTask.TaskId, progress.Value.TotalMilliseconds);262 });263 switch (curTask.Command) {264 case DA.Command.Stop:265 actions.Add(new MessageContainer(MessageContainer.MessageType.StopTask, curTask.TaskId));266 break;267 case DA.Command.Pause:268 actions.Add(new MessageContainer(MessageContainer.MessageType.PauseTask, curTask.TaskId));269 break;270 case DA.Command.Abort:271 actions.Add(new MessageContainer(MessageContainer.MessageType.AbortTask, curTask.TaskId));272 break;273 }274 }275 }276 }277 }278 return actions;279 }280 214 } 281 215 }
Note: See TracChangeset
for help on using the changeset viewer.