Mercurial > hg > orthanc
changeset 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 | 47d812308d63 |
children | a21b244efb37 |
files | Core/JobsEngine/IJob.h Core/JobsEngine/JobStatus.cpp Core/JobsEngine/JobStatus.h Core/JobsEngine/JobsRegistry.cpp Core/JobsEngine/Operations/SequenceOfOperationsJob.cpp Core/JobsEngine/Operations/SequenceOfOperationsJob.h Core/JobsEngine/SetOfInstancesJob.cpp Core/JobsEngine/SetOfInstancesJob.h OrthancServer/ServerJobs/ArchiveJob.cpp OrthancServer/ServerJobs/ArchiveJob.h OrthancServer/ServerJobs/ResourceModificationJob.cpp OrthancServer/ServerJobs/ResourceModificationJob.h UnitTestsSources/MultiThreadingTests.cpp |
diffstat | 13 files changed, 88 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/JobsEngine/IJob.h Thu Jun 07 17:47:41 2018 +0200 +++ b/Core/JobsEngine/IJob.h Thu Jun 07 18:18:02 2018 +0200 @@ -63,6 +63,6 @@ virtual void GetPublicContent(Json::Value& value) = 0; - virtual void Serialize(Json::Value& value) = 0; + virtual bool Serialize(Json::Value& value) = 0; }; }
--- a/Core/JobsEngine/JobStatus.cpp Thu Jun 07 17:47:41 2018 +0200 +++ b/Core/JobsEngine/JobStatus.cpp Thu Jun 07 18:18:02 2018 +0200 @@ -34,6 +34,8 @@ #include "../PrecompiledHeaders.h" #include "JobStatus.h" +#include "../OrthancException.h" + namespace Orthanc { JobStatus::JobStatus() : @@ -41,7 +43,7 @@ progress_(0), jobType_("Invalid"), publicContent_(Json::objectValue), - serialized_(Json::objectValue) + hasSerialized_(false) { } @@ -64,6 +66,20 @@ job.GetJobType(jobType_); job.GetPublicContent(publicContent_); - job.Serialize(serialized_); + + hasSerialized_ = job.Serialize(serialized_); + } + + + const Json::Value& JobStatus::GetSerialized() const + { + if (!hasSerialized_) + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + return serialized_; + } } }
--- a/Core/JobsEngine/JobStatus.h Thu Jun 07 17:47:41 2018 +0200 +++ b/Core/JobsEngine/JobStatus.h Thu Jun 07 18:18:02 2018 +0200 @@ -45,6 +45,7 @@ std::string jobType_; Json::Value publicContent_; Json::Value serialized_; + bool hasSerialized_; public: JobStatus(); @@ -77,9 +78,11 @@ return publicContent_; } - const Json::Value& GetSerialized() const + const Json::Value& GetSerialized() const; + + bool HasSerialized() const { - return serialized_; + return hasSerialized_; } }; }
--- 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); + } } }
--- a/Core/JobsEngine/Operations/SequenceOfOperationsJob.cpp Thu Jun 07 17:47:41 2018 +0200 +++ b/Core/JobsEngine/Operations/SequenceOfOperationsJob.cpp Thu Jun 07 18:18:02 2018 +0200 @@ -361,7 +361,7 @@ } - void SequenceOfOperationsJob::Serialize(Json::Value& value) + bool SequenceOfOperationsJob::Serialize(Json::Value& value) { boost::mutex::scoped_lock lock(mutex_); @@ -377,5 +377,7 @@ value["TrailingTimeout"] = static_cast<unsigned int>(trailingTimeout_.total_milliseconds()); value["DicomTimeout"] = connectionManager_.GetTimeout(); value["Current"] = static_cast<unsigned int>(current_); + + return true; } }
--- a/Core/JobsEngine/Operations/SequenceOfOperationsJob.h Thu Jun 07 17:47:41 2018 +0200 +++ b/Core/JobsEngine/Operations/SequenceOfOperationsJob.h Thu Jun 07 18:18:02 2018 +0200 @@ -138,7 +138,7 @@ virtual void GetPublicContent(Json::Value& value); - virtual void Serialize(Json::Value& value); + virtual bool Serialize(Json::Value& value); void AwakeTrailingSleep() {
--- a/Core/JobsEngine/SetOfInstancesJob.cpp Thu Jun 07 17:47:41 2018 +0200 +++ b/Core/JobsEngine/SetOfInstancesJob.cpp Thu Jun 07 18:18:02 2018 +0200 @@ -200,7 +200,7 @@ } - void SetOfInstancesJob::Serialize(Json::Value& value) + bool SetOfInstancesJob::Serialize(Json::Value& value) { value = Json::objectValue; @@ -214,6 +214,8 @@ SerializationToolbox::WriteArrayOfStrings(value, instances_, "Instances"); SerializationToolbox::WriteSetOfStrings(value, failedInstances_, "FailedInstances"); + + return true; }
--- a/Core/JobsEngine/SetOfInstancesJob.h Thu Jun 07 17:47:41 2018 +0200 +++ b/Core/JobsEngine/SetOfInstancesJob.h Thu Jun 07 18:18:02 2018 +0200 @@ -118,6 +118,6 @@ virtual void GetPublicContent(Json::Value& value); - virtual void Serialize(Json::Value& value); + virtual bool Serialize(Json::Value& value); }; }
--- a/OrthancServer/ServerJobs/ArchiveJob.cpp Thu Jun 07 17:47:41 2018 +0200 +++ b/OrthancServer/ServerJobs/ArchiveJob.cpp Thu Jun 07 18:18:02 2018 +0200 @@ -901,10 +901,4 @@ value["UncompressedSizeMB"] = static_cast<unsigned int>(uncompressedSize_ / MEGA_BYTES); } - - - void ArchiveJob::Serialize(Json::Value& value) - { - // TODO - } }
--- a/OrthancServer/ServerJobs/ArchiveJob.h Thu Jun 07 17:47:41 2018 +0200 +++ b/OrthancServer/ServerJobs/ArchiveJob.h Thu Jun 07 18:18:02 2018 +0200 @@ -97,6 +97,9 @@ virtual void GetPublicContent(Json::Value& value); - virtual void Serialize(Json::Value& value); + virtual bool Serialize(Json::Value& value) + { + return false; // Cannot serialize this kind of job + } }; }
--- a/OrthancServer/ServerJobs/ResourceModificationJob.cpp Thu Jun 07 17:47:41 2018 +0200 +++ b/OrthancServer/ServerJobs/ResourceModificationJob.cpp Thu Jun 07 18:18:02 2018 +0200 @@ -273,12 +273,14 @@ } - void ResourceModificationJob::Serialize(Json::Value& value) + bool ResourceModificationJob::Serialize(Json::Value& value) { SetOfInstancesJob::Serialize(value); Json::Value tmp; modification_->Serialize(tmp); value["Modification"] = tmp; + + return true; } }
--- a/OrthancServer/ServerJobs/ResourceModificationJob.h Thu Jun 07 17:47:41 2018 +0200 +++ b/OrthancServer/ServerJobs/ResourceModificationJob.h Thu Jun 07 18:18:02 2018 +0200 @@ -104,6 +104,6 @@ virtual void GetPublicContent(Json::Value& value); - virtual void Serialize(Json::Value& value); + virtual bool Serialize(Json::Value& value); }; }
--- a/UnitTestsSources/MultiThreadingTests.cpp Thu Jun 07 17:47:41 2018 +0200 +++ b/UnitTestsSources/MultiThreadingTests.cpp Thu Jun 07 18:18:02 2018 +0200 @@ -58,6 +58,8 @@ #include "../OrthancServer/ServerJobs/Operations/StoreScuOperation.h" #include "../OrthancServer/ServerJobs/Operations/SystemCallOperation.h" +#include "../OrthancServer/ServerJobs/ArchiveJob.h" + using namespace Orthanc; @@ -125,8 +127,9 @@ type = "DummyJob"; } - virtual void Serialize(Json::Value& value) + virtual bool Serialize(Json::Value& value) { + return true; } virtual void GetPublicContent(Json::Value& value) @@ -863,7 +866,7 @@ job.Start(); job.ExecuteStep(); job.ExecuteStep(); - job.Serialize(s); + ASSERT_TRUE(job.Serialize(s)); } { @@ -1144,7 +1147,15 @@ TEST_F(OrthancJobsSerialization, Jobs) { - // TODO : ArchiveJob + // ArchiveJob + + Json::Value s; + + { + boost::shared_ptr<TemporaryFile> tmp(new TemporaryFile); + ArchiveJob job(tmp, GetContext(), false, false); + ASSERT_FALSE(job.Serialize(s)); + } // TODO : DicomModalityStoreJob