diff OrthancServer/ServerJobs/LuaJobManager.cpp @ 2620:1232922c8793 jobs

speeding up shutdown if Lua script is in trailing phase
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 22 May 2018 14:08:57 +0200
parents 2f3007bf0708
children 714dcddeb65f
line wrap: on
line diff
--- a/OrthancServer/ServerJobs/LuaJobManager.cpp	Tue May 22 13:11:47 2018 +0200
+++ b/OrthancServer/ServerJobs/LuaJobManager.cpp	Tue May 22 14:08:57 2018 +0200
@@ -34,6 +34,9 @@
 #include "../PrecompiledHeadersServer.h"
 #include "LuaJobManager.h"
 
+#include "../OrthancInitialization.h"
+#include "../../Core/Logging.h"
+
 #include "../../Core/JobsEngine/Operations/LogJobOperation.h"
 #include "DeleteResourceOperation.h"
 #include "ModifyInstanceOperation.h"
@@ -65,6 +68,9 @@
     priority_(0),
     trailingTimeout_(5000)
   {
+    dicomTimeout_ = Configuration::GetGlobalUnsignedIntegerParameter("DicomAssociationCloseDelay", 5);
+    LOG(INFO) << "Lua: DICOM associations will be closed after "
+              << dicomTimeout_ << " seconds of inactivity";
   }
 
 
@@ -89,6 +95,19 @@
   }
 
 
+  void LuaJobManager::AwakeTrailingSleep()
+  {
+    boost::mutex::scoped_lock lock(mutex_);
+
+    LOG(INFO) << "Awaking trailing sleep";
+
+    if (currentJob_ != NULL)
+    {
+      currentJob_->AwakeTrailingSleep();
+    }
+  }
+
+
   LuaJobManager::Lock::Lock(LuaJobManager& that,
                             JobsEngine& engine) :
     that_(that),
@@ -125,6 +144,7 @@
       {
         jobLock_.reset(new SequenceOfOperationsJob::Lock(*that_.currentJob_));
         jobLock_->SetTrailingOperationTimeout(that_.trailingTimeout_);
+        jobLock_->SetDicomAssociationTimeout(that_.dicomTimeout_ * 1000);  // Milliseconds expected
       }
     }