changeset 6734:cba457078ce8

lazy starting of loader threads in StoreJob + fix OrthancPeerStore loader threads usage
author Alain Mazy <am@orthanc.team>
date Wed, 22 Apr 2026 13:09:28 +0200
parents 73cb29fd7eb5
children 8594adfe25e2
files NEWS OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp OrthancServer/Sources/ServerJobs/StoreJob.cpp OrthancServer/Sources/ServerJobs/StoreJob.h
diffstat 5 files changed, 23 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed Apr 22 12:26:28 2026 +0200
+++ b/NEWS	Wed Apr 22 13:09:28 2026 +0200
@@ -25,8 +25,10 @@
 Maintenance
 -----------
 
-* Fix /jobs/.../resubmit for OrthancPeerStore and DicomModalityStore jobs 
+* Fix resubmit/pause/cancel and reloading of OrthancPeerStore and DicomModalityStore jobs 
   (bug introduced in 1.12.10)
+* Fix OrthancPeerStore jobs that was using the loader threads only if transcoding
+  was required.
 * Fix Orthanc::ImageAccessor that was broken in Orthanc Framework 1.12.11
 
 
--- a/OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp	Wed Apr 22 12:26:28 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/DicomModalityStoreJob.cpp	Wed Apr 22 13:09:28 2026 +0200
@@ -48,6 +48,11 @@
     assert(IsStarted());
     OpenConnection();
 
+    if (instancesLoader_.get() == NULL)
+    {
+      StartLoaderThreads();
+    }
+
     LOG(INFO) << "Sending instance " << instance << " to modality \"" 
               << parameters_.GetRemoteModality().GetApplicationEntityTitle() << "\"";
 
--- a/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp	Wed Apr 22 12:26:28 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/OrthancPeerStoreJob.cpp	Wed Apr 22 13:09:28 2026 +0200
@@ -36,7 +36,10 @@
 {
   bool OrthancPeerStoreJob::HandleInstance(const std::string& instance)
   {
-    //boost::this_thread::sleep(boost::posix_time::milliseconds(500));
+    if (instancesLoader_.get() == NULL)
+    {
+      StartLoaderThreads();
+    }
 
     if (client_.get() == NULL)
     {
@@ -58,11 +61,11 @@
 
     try
     {
+      std::string dicom;
+      instancesLoader_->WaitDicomInstance(dicom, instance);
+
       if (transcode_)
       {
-        std::string dicom;
-        instancesLoader_->WaitDicomInstance(dicom, instance);
-
         std::set<DicomTransferSyntax> syntaxes;
         syntaxes.insert(transferSyntax_);
         
@@ -81,7 +84,7 @@
       }
       else
       {
-        context_.ReadDicom(body, instance);
+        body.swap(dicom);
       }
     }
     catch (OrthancException& e)
--- a/OrthancServer/Sources/ServerJobs/StoreJob.cpp	Wed Apr 22 12:26:28 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/StoreJob.cpp	Wed Apr 22 13:09:28 2026 +0200
@@ -81,16 +81,8 @@
     }
   }
 
-  void StoreJob::Reset()  // called in case of "resubmit"
-  {
-    SetOfInstancesJob::Reset();
-    
-    // restart the loader threads here (this can happen quite long before the job starts actually being executed but this is the only place where we can do this)
-    Start();
-  }
 
-
-  void StoreJob::Start()
+  void StoreJob::StartLoaderThreads()
   {
     size_t loaderThreads = 1;
     {
@@ -105,23 +97,12 @@
     {
       instancesLoader_->PreloadDicomInstance(instancesIds_[i], filesInfo_[i]);
     }
-
-    SetOfInstancesJob::Start();
   }
 
-
-  void StoreJob::Stop(JobStopReason reason)   // For pausing jobs
+  
+  void StoreJob::Stop(JobStopReason reason)
   {
-    if (reason == JobStopReason_Canceled ||
-        reason == JobStopReason_Failure ||
-        reason == JobStopReason_Retry ||
-        reason == JobStopReason_Success)
-    {
-      // clear the loader threads
-      if (instancesLoader_.get() != NULL)
-      {
-        instancesLoader_->Clear(true);
-      }
-    }
+    // clear the loader threads (also when simply pausing the job)
+    instancesLoader_.reset(NULL);
   }
 }
--- a/OrthancServer/Sources/ServerJobs/StoreJob.h	Wed Apr 22 12:26:28 2026 +0200
+++ b/OrthancServer/Sources/ServerJobs/StoreJob.h	Wed Apr 22 13:09:28 2026 +0200
@@ -44,16 +44,14 @@
 
     virtual const char* GetLoaderPrefix() const = 0;
 
+    void StartLoaderThreads();
+
   public:
     explicit StoreJob(ServerContext& context);
 
     StoreJob(ServerContext& context,
              const Json::Value& serialized);
 
-    virtual void Reset() ORTHANC_OVERRIDE;
-    
-    virtual void Start() ORTHANC_OVERRIDE;
-
     virtual void Stop(JobStopReason reason) ORTHANC_OVERRIDE;
 
     void AddInstances(const std::vector<std::string>& instancesIds,