diff Core/JobsEngine/JobsRegistry.cpp @ 2669:eaf10085ffa1 jobs

no passwords in public content of jobs
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 09 Jun 2018 14:15:32 +0200
parents d26dd081df97
children c5646f766b3e
line wrap: on
line diff
--- a/Core/JobsEngine/JobsRegistry.cpp	Fri Jun 08 18:08:48 2018 +0200
+++ b/Core/JobsEngine/JobsRegistry.cpp	Sat Jun 09 14:15:32 2018 +0200
@@ -50,6 +50,7 @@
   static const char* JOBS_REGISTRY = "JobsRegistry";
   static const char* MAX_COMPLETED_JOBS = "MaxCompletedJobs";
   static const char* CREATION_TIME = "CreationTime";
+  static const char* LAST_CHANGE_TIME = "LastChangeTime";
   static const char* RUNTIME = "Runtime";
   
 
@@ -226,6 +227,11 @@
       return lastStateChangeTime_;
     }
 
+    void SetLastStateChangeTime(const boost::posix_time::ptime& time)
+    {
+      lastStateChangeTime_ = time;
+    }
+
     const boost::posix_time::time_duration& GetRuntime() const
     {
       return runtime_;
@@ -282,6 +288,7 @@
         target[STATE] = EnumerationToString(state_);
         target[PRIORITY] = priority_;
         target[CREATION_TIME] = boost::posix_time::to_iso_string(creationTime_);
+        target[LAST_CHANGE_TIME] = boost::posix_time::to_iso_string(lastStateChangeTime_);
         target[RUNTIME] = static_cast<unsigned int>(runtime_.total_milliseconds());
         return true;
       }
@@ -294,7 +301,6 @@
 
     JobHandler(IJobUnserializer& unserializer,
                const Json::Value& serialized) :
-      lastStateChangeTime_(boost::posix_time::microsec_clock::universal_time()),
       pauseScheduled_(false),
       cancelScheduled_(false)
     {
@@ -303,17 +309,13 @@
       priority_ = SerializationToolbox::ReadInteger(serialized, PRIORITY);
       creationTime_ = boost::posix_time::from_iso_string
         (SerializationToolbox::ReadString(serialized, CREATION_TIME));
+      lastStateChangeTime_ = boost::posix_time::from_iso_string
+        (SerializationToolbox::ReadString(serialized, LAST_CHANGE_TIME));
       runtime_ = boost::posix_time::milliseconds
         (SerializationToolbox::ReadInteger(serialized, RUNTIME));
 
       retryTime_ = creationTime_;
 
-      if (state_ == JobState_Retry ||
-          state_ == JobState_Running) 
-      {
-        state_ = JobState_Pending;
-      }
-
       job_.reset(unserializer.UnserializeJob(serialized[JOB]));
       job_->GetJobType(jobType_);
       job_->Start();
@@ -591,7 +593,8 @@
 
 
   void JobsRegistry::SubmitInternal(std::string& id,
-                                    JobHandler* handlerRaw)
+                                    JobHandler* handlerRaw,
+                                    bool keepLastChangeTime)
   {
     if (handlerRaw == NULL)
     {
@@ -600,6 +603,8 @@
     
     std::auto_ptr<JobHandler>  handler(handlerRaw);
 
+    boost::posix_time::ptime lastChangeTime = handler->GetLastStateChangeTime();
+
     boost::mutex::scoped_lock lock(mutex_);
     CheckInvariants();
       
@@ -633,6 +638,11 @@
         throw OrthancException(ErrorCode_InternalError);
     }
 
+    if (keepLastChangeTime)
+    {
+      handler->SetLastStateChangeTime(lastChangeTime);
+    }
+    
     jobsIndex_.insert(std::make_pair(id, handler.release()));
 
     LOG(INFO) << "New job submitted with priority " << priority << ": " << id;
@@ -645,7 +655,7 @@
                             IJob* job,        // Takes ownership
                             int priority)
   {
-    SubmitInternal(id, new JobHandler(job, priority));
+    SubmitInternal(id, new JobHandler(job, priority), false);
   }
 
 
@@ -653,7 +663,7 @@
                             int priority)
   {
     std::string id;
-    SubmitInternal(id, new JobHandler(job, priority));
+    SubmitInternal(id, new JobHandler(job, priority), false);
   }
 
 
@@ -1250,9 +1260,9 @@
     for (Json::Value::ArrayIndex i = 0; i < s[JOBS].size(); i++)
     {
       std::auto_ptr<JobHandler> job(new JobHandler(unserializer, s[JOBS][i]));
-
+      
       std::string id;
-      SubmitInternal(id, job.release());
+      SubmitInternal(id, job.release(), true);
     }
   }
 }