diff Core/JobsEngine/JobsRegistry.cpp @ 3177:053e72ff9fc5

new metrics: orthanc_jobs_[pending|running|completed]
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Jan 2019 10:24:12 +0100
parents 94a4f75cc746
children fca730c267d7
line wrap: on
line diff
--- a/Core/JobsEngine/JobsRegistry.cpp	Tue Jan 29 18:07:41 2019 +0100
+++ b/Core/JobsEngine/JobsRegistry.cpp	Wed Jan 30 10:24:12 2019 +0100
@@ -1398,4 +1398,44 @@
       }
     }
   }
+
+
+  void JobsRegistry::GetStatistics(unsigned int& pending,
+                                   unsigned int& running,
+                                   unsigned int& completed)
+  {
+    boost::mutex::scoped_lock lock(mutex_);
+    CheckInvariants();
+
+    pending = 0;
+    running = 0;
+    completed = 0;
+    
+    for (JobsIndex::const_iterator it = jobsIndex_.begin();
+         it != jobsIndex_.end(); ++it)
+    {
+      JobHandler& job = *it->second;
+
+      switch (job.GetState())
+      {
+        case JobState_Retry:
+        case JobState_Paused:
+        case JobState_Pending:
+          pending ++;
+          break;
+
+        case JobState_Running:
+          running ++;
+          break;
+          
+        case JobState_Success:
+        case JobState_Failure:
+          completed ++;
+          break;
+
+        default:
+          throw OrthancException(ErrorCode_InternalError);
+      }
+    }    
+  }
 }