private KMeansTask TaskResultWithTaskID(Guid guid) { KMeansTask foundTask = null; foreach (KMeansTask task in tasks) { if (task.TaskData.TaskID == guid && task.Running) { foundTask = task; break; } } return(foundTask); }
/// <summary> /// Handles a worker's TaskResult from a running k-means job. Adds up the partial sums from the TaskResult. /// </summary> /// <param name="message"></param> /// <returns>False if the given taskData result has already been counted, true otherwise.</returns> public bool ProcessWorkerResponse(KMeansTaskResult taskResult, IEnumerable <Worker> workers) { // Make sure we're actually still waiting for a result for this taskData // If not, this might be a duplicate queue message if (!TaskResultMatchesRunningTask(taskResult)) { return(true); } AzureHelper.LogPerformance(() => { KMeansTask task = TaskResultWithTaskID(taskResult.TaskID); task.Running = false; // The task has returned a response, which means that it has stopped running // Add the worker's updated points blocks if (taskResult.PointsBlockListBlob != null) { using (Stream stream = AzureHelper.GetBlob(taskResult.PointsBlockListBlob).OpenRead()) { BinaryFormatter bf = new BinaryFormatter(); List <string> pointsBlockList = bf.Deserialize(stream) as List <string>; pointsBlockIDs.AddRange(pointsBlockList); } } // Copy out and integrate the data from the worker response AddDataFromTaskResult(taskResult); }, jobData.JobID.ToString(), methodName: "ProcessWorkerResponse", iterationCount: IterationCount, points: Points.Uri.ToString(), centroids: Centroids.Uri.ToString(), machineID: MachineID); // If this is the last worker to return, this iteration is done and we should start the next one if (NoMoreRunningTasks()) { NextIteration(workers); } return(true); }
private bool TaskResultMatchesRunningTask(KMeansTaskResult taskResult) { KMeansTask task = TaskResultWithTaskID(taskResult.TaskID); return(task != null && task.Running); }