diff Core/JobsEngine/JobsEngine.cpp @ 2573:3372c5255333 jobs

StoreScuJob, Orthanc Explorer for jobs
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 09 May 2018 17:56:14 +0200
parents 2e879c796ec7
children 8da2cffc2378
line wrap: on
line diff
--- a/Core/JobsEngine/JobsEngine.cpp	Mon May 07 21:42:04 2018 +0200
+++ b/Core/JobsEngine/JobsEngine.cpp	Wed May 09 17:56:14 2018 +0200
@@ -41,14 +41,18 @@
 
 namespace Orthanc
 {
+  bool JobsEngine::IsRunning()
+  {
+    boost::mutex::scoped_lock lock(stateMutex_);
+    return (state_ == State_Running);
+  }
+  
+  
   bool JobsEngine::ExecuteStep(JobsRegistry::RunningJob& running,
                                size_t workerIndex)
   {
     assert(running.IsValid());
 
-    LOG(INFO) << "Executing job with priority " << running.GetPriority()
-              << " in worker thread " << workerIndex << ": " << running.GetId();
-
     if (running.IsPauseScheduled())
     {
       running.GetJob().ReleaseResources();
@@ -94,10 +98,12 @@
     switch (result->GetCode())
     {
       case JobStepCode_Success:
+        running.GetJob().ReleaseResources();
         running.MarkSuccess();
         return false;
 
       case JobStepCode_Failure:
+        running.GetJob().ReleaseResources();
         running.MarkFailure();
         return false;
 
@@ -119,19 +125,9 @@
   {
     assert(engine != NULL);
 
-    for (;;)
+    while (engine->IsRunning())
     {
       boost::this_thread::sleep(boost::posix_time::milliseconds(200));
-
-      {
-        boost::mutex::scoped_lock lock(engine->stateMutex_);
-
-        if (engine->state_ != State_Running)
-        {
-          return;
-        }
-      }
-
       engine->GetRegistry().ScheduleRetries();
     }
   }
@@ -144,22 +140,16 @@
 
     LOG(INFO) << "Worker thread " << workerIndex << " has started";
 
-    for (;;)
+    while (engine->IsRunning())
     {
-      {
-        boost::mutex::scoped_lock lock(engine->stateMutex_);
-
-        if (engine->state_ != State_Running)
-        {
-          return;
-        }
-      }
-
       JobsRegistry::RunningJob running(engine->GetRegistry(), 100);
 
       if (running.IsValid())
       {
-        for (;;)
+        LOG(INFO) << "Executing job with priority " << running.GetPriority()
+                  << " in worker thread " << workerIndex << ": " << running.GetId();
+
+        while (engine->IsRunning())
         {
           if (!engine->ExecuteStep(running, workerIndex))
           {