Mercurial > hg > orthanc
diff Core/JobsEngine/JobsRegistry.cpp @ 2663:228e2783ce83 jobs
some jobs might not be serializable
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 07 Jun 2018 18:18:02 +0200 |
parents | a6d3e45eeff5 |
children | 5fa2f2ce74f0 |
line wrap: on
line diff
--- a/Core/JobsEngine/JobsRegistry.cpp Thu Jun 07 17:47:41 2018 +0200 +++ b/Core/JobsEngine/JobsRegistry.cpp Thu Jun 07 18:18:02 2018 +0200 @@ -235,15 +235,11 @@ lastStatus_.SetErrorCode(code); } - void Serialize(Json::Value& target) const + bool Serialize(Json::Value& target) const { target = Json::objectValue; - target["ID"] = id_; - target["State"] = EnumerationToString(state_); - target["JobType"] = jobType_; - target["Priority"] = priority_; - target["CreationTime"] = boost::posix_time::to_iso_string(creationTime_); - target["Runtime"] = static_cast<unsigned int>(runtime_.total_milliseconds()); + + bool ok; if (state_ == JobState_Running) { @@ -252,11 +248,36 @@ // mutex at the "JobHandler" level, as serialization would be // blocked while a step in the job is running. Instead, we // save a snapshot of the serialized job. - target["Job"] = lastStatus_.GetSerialized(); + + if (lastStatus_.HasSerialized()) + { + target["Job"] = lastStatus_.GetSerialized(); + ok = true; + } + else + { + ok = false; + } + } + else + { + ok = job_->Serialize(target["Job"]); + } + + if (ok) + { + target["ID"] = id_; + target["State"] = EnumerationToString(state_); + target["JobType"] = jobType_; + target["Priority"] = priority_; + target["CreationTime"] = boost::posix_time::to_iso_string(creationTime_); + target["Runtime"] = static_cast<unsigned int>(runtime_.total_milliseconds()); + return true; } else { - job_->Serialize(target["Job"]); + LOG(WARNING) << "Job backup is not supported for job of type: " << jobType_; + return false; } } @@ -568,8 +589,10 @@ it != jobsIndex_.end(); ++it) { Json::Value v; - it->second->Serialize(v); - target.append(v); + if (it->second->Serialize(v)) + { + target.append(v); + } } }