# HG changeset patch # User Sebastien Jodogne # Date 1528388282 -7200 # Node ID 228e2783ce8368e3cc7872a5521e4f8bc20f4c37 # Parent 47d812308d637fd01a427b6b63c676158e35c69c some jobs might not be serializable diff -r 47d812308d63 -r 228e2783ce83 Core/JobsEngine/IJob.h --- 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; }; } diff -r 47d812308d63 -r 228e2783ce83 Core/JobsEngine/JobStatus.cpp --- 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_; + } } } diff -r 47d812308d63 -r 228e2783ce83 Core/JobsEngine/JobStatus.h --- 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_; } }; } diff -r 47d812308d63 -r 228e2783ce83 Core/JobsEngine/JobsRegistry.cpp --- 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(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(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); + } } } diff -r 47d812308d63 -r 228e2783ce83 Core/JobsEngine/Operations/SequenceOfOperationsJob.cpp --- 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(trailingTimeout_.total_milliseconds()); value["DicomTimeout"] = connectionManager_.GetTimeout(); value["Current"] = static_cast(current_); + + return true; } } diff -r 47d812308d63 -r 228e2783ce83 Core/JobsEngine/Operations/SequenceOfOperationsJob.h --- 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() { diff -r 47d812308d63 -r 228e2783ce83 Core/JobsEngine/SetOfInstancesJob.cpp --- 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; } diff -r 47d812308d63 -r 228e2783ce83 Core/JobsEngine/SetOfInstancesJob.h --- 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); }; } diff -r 47d812308d63 -r 228e2783ce83 OrthancServer/ServerJobs/ArchiveJob.cpp --- 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(uncompressedSize_ / MEGA_BYTES); } - - - void ArchiveJob::Serialize(Json::Value& value) - { - // TODO - } } diff -r 47d812308d63 -r 228e2783ce83 OrthancServer/ServerJobs/ArchiveJob.h --- 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 + } }; } diff -r 47d812308d63 -r 228e2783ce83 OrthancServer/ServerJobs/ResourceModificationJob.cpp --- 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; } } diff -r 47d812308d63 -r 228e2783ce83 OrthancServer/ServerJobs/ResourceModificationJob.h --- 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); }; } diff -r 47d812308d63 -r 228e2783ce83 UnitTestsSources/MultiThreadingTests.cpp --- 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 tmp(new TemporaryFile); + ArchiveJob job(tmp, GetContext(), false, false); + ASSERT_FALSE(job.Serialize(s)); + } // TODO : DicomModalityStoreJob