diff Core/JobsEngine/JobsRegistry.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/JobsRegistry.cpp	Mon May 07 21:42:04 2018 +0200
+++ b/Core/JobsEngine/JobsRegistry.cpp	Wed May 09 17:56:14 2018 +0200
@@ -520,7 +520,7 @@
   }
 
 
-  void JobsRegistry::SetPriority(const std::string& id,
+  bool JobsRegistry::SetPriority(const std::string& id,
                                  int priority)
   {
     LOG(INFO) << "Changing priority to " << priority << " for job: " << id;
@@ -533,6 +533,7 @@
     if (found == jobsIndex_.end())
     {
       LOG(WARNING) << "Unknown job: " << id;
+      return false;
     }
     else
     {
@@ -553,13 +554,14 @@
           copy.pop();
         }
       }
+
+      CheckInvariants();
+      return true;
     }
-
-    CheckInvariants();
   }
 
 
-  void JobsRegistry::Pause(const std::string& id)
+  bool JobsRegistry::Pause(const std::string& id)
   {
     LOG(INFO) << "Pausing job: " << id;
 
@@ -571,6 +573,7 @@
     if (found == jobsIndex_.end())
     {
       LOG(WARNING) << "Unknown job: " << id;
+      return false;
     }
     else
     {
@@ -623,13 +626,14 @@
         default:
           throw OrthancException(ErrorCode_InternalError);
       }
+
+      CheckInvariants();
+      return true;
     }
-
-    CheckInvariants();
   }
 
 
-  void JobsRegistry::Resume(const std::string& id)
+  bool JobsRegistry::Resume(const std::string& id)
   {
     LOG(INFO) << "Resuming job: " << id;
 
@@ -641,23 +645,25 @@
     if (found == jobsIndex_.end())
     {
       LOG(WARNING) << "Unknown job: " << id;
+      return false;
     }
     else if (found->second->GetState() != JobState_Paused)
     {
       LOG(WARNING) << "Cannot resume a job that is not paused: " << id;
+      return false;
     }
     else
     {
       found->second->SetState(JobState_Pending);
       pendingJobs_.push(found->second);
       pendingJobAvailable_.notify_one();
+      CheckInvariants();
+      return true;      
     }
-
-    CheckInvariants();
   }
 
 
-  void JobsRegistry::Resubmit(const std::string& id)
+  bool JobsRegistry::Resubmit(const std::string& id)
   {
     LOG(INFO) << "Resubmitting failed job: " << id;
 
@@ -669,10 +675,12 @@
     if (found == jobsIndex_.end())
     {
       LOG(WARNING) << "Unknown job: " << id;
+      return false;
     }
     else if (found->second->GetState() != JobState_Failure)
     {
       LOG(WARNING) << "Cannot resubmit a job that has not failed: " << id;
+      return false;
     }
     else
     {
@@ -693,9 +701,10 @@
       found->second->SetState(JobState_Pending);
       pendingJobs_.push(found->second);
       pendingJobAvailable_.notify_one();
+
+      CheckInvariants();
+      return true;
     }
-
-    CheckInvariants();
   }