diff Core/JobsEngine/JobsRegistry.cpp @ 2867:251614c2edac

DicomMoveScuJob
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 08 Oct 2018 16:08:51 +0200
parents 859a4950d48f
children 577786f59252
line wrap: on
line diff
--- a/Core/JobsEngine/JobsRegistry.cpp	Mon Oct 08 11:40:31 2018 +0200
+++ b/Core/JobsEngine/JobsRegistry.cpp	Mon Oct 08 16:08:51 2018 +0200
@@ -685,22 +685,53 @@
   }
 
 
-  bool JobsRegistry::SubmitAndWait(IJob* job,        // Takes ownership
+  bool JobsRegistry::SubmitAndWait(Json::Value& successContent,
+                                   IJob* job,        // Takes ownership
                                    int priority)
   {
     std::string id;
     Submit(id, job, priority);
 
-    JobState state = JobState_Pending;
+    JobState state = JobState_Pending;  // Dummy initialization
 
     {
       boost::mutex::scoped_lock lock(mutex_);
 
-      while (GetStateInternal(state, id) &&
-             state != JobState_Success &&
-             state != JobState_Failure)
+      for (;;)
       {
-        someJobComplete_.wait(lock);
+        if (!GetStateInternal(state, id))
+        {
+          // Job has finished and has been lost (should not happen)
+          state = JobState_Failure;
+          break;
+        }
+        else if (state == JobState_Failure)
+        {
+          // Failure
+          break;
+        }
+        else if (state == JobState_Success)
+        {
+          // Success, try and retrieve the status of the job
+          JobsIndex::const_iterator it = jobsIndex_.find(id);
+          if (it == jobsIndex_.end())
+          {
+            // Should not happen
+            state = JobState_Failure;
+          }
+          else
+          {
+            const JobStatus& status = it->second->GetLastStatus();
+            successContent = status.GetPublicContent();
+          }
+          
+          break;
+        }
+        else
+        {
+          // This job has not finished yet, wait for new completion
+          someJobComplete_.wait(lock);
+        }
       }
     }