Ejemplo n.º 1
0
        // If the results were not good enough, or aggregation method changed, retargeted, users might want to reopen the job
        // All we need to do: (IN STRICT ORDER)

        //      clear all results back to inconclusive,
        //      remove all aggregated results
        //      restore the task table as it was for the guid,
        //      change the job status back to launched, and
        // WARNING:
        //      for safety, this has to be run atomically synchronously, without any parallel process. for now.
        public static void reopenJobForMoreResults(string guid)
        {
            SatyamJobSubmissionsTableAccess      jobDB    = new SatyamJobSubmissionsTableAccess();
            SatyamJobSubmissionsTableAccessEntry jobEntry = jobDB.getEntryByJobGIUD(guid);

            jobDB.close();

            if (jobEntry.JobStatus != JobStatus.completed)
            {
                Console.WriteLine("Job not completed yet!");
                return;
            }

            SatyamAggregatedResultsTableAccess aggResultDB = new SatyamAggregatedResultsTableAccess();
            bool delSuccess = aggResultDB.DeleteEntriesByGUID(guid);

            aggResultDB.close();
            if (!delSuccess)
            {
                Console.WriteLine("Delete Agg Result DB Failed");
                return;
            }

            SatyamResultsTableAccess resultDB = new SatyamResultsTableAccess();

            if (!resultDB.UpdateStatusByGUID(guid, ResultStatus.inconclusive))
            {
                Console.WriteLine("Update Result DB Failed");
                //resultDB.close();
                //return;
            }


            List <SatyamResultsTableEntry> results = resultDB.getEntriesByGUID(guid);

            resultDB.close();
            Dictionary <int, SatyamTask> taskParamsByTaskID = new Dictionary <int, SatyamTask>();

            foreach (SatyamResultsTableEntry result in results)
            {
                if (taskParamsByTaskID.ContainsKey(result.SatyamTaskTableEntryID))
                {
                    continue;
                }

                SatyamResult satyamRes = JSonUtils.ConvertJSonToObject <SatyamResult>(result.ResultString);
                SatyamTask   task      = JSonUtils.ConvertJSonToObject <SatyamTask>(satyamRes.TaskParametersString);
                taskParamsByTaskID.Add(result.SatyamTaskTableEntryID, task);
            }

            SatyamTaskTableAccess taskDB = new SatyamTaskTableAccess();

            foreach (int taskID in taskParamsByTaskID.Keys)
            {
                SatyamTask task = taskParamsByTaskID[taskID];
                SatyamJob  job  = task.jobEntry;
                bool       suc  = taskDB.AddEntryWithSpecificID(taskID, job.JobTemplateType, job.UserID, job.JobGUIDString, JSonUtils.ConvertObjectToJSon(task),
                                                                job.JobSubmitTime, job.amazonHITInformation.Price);
                if (!suc)
                {
                    Console.WriteLine("Update Task Table Failed");
                    taskDB.close();
                    return;
                }
            }
            taskDB.close();

            jobDB = new SatyamJobSubmissionsTableAccess();
            bool success = jobDB.UpdateEntryStatus(guid, JobStatus.launched);

            jobDB.close();
            if (!success)
            {
                Console.WriteLine("Update Job Entry Failed");
                return;
            }
        }