changeset 1099:060e8918d7a4

More fault-tolerant commands in Lua scripts
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 07 Aug 2014 10:02:22 +0200
parents 50c889af583b
children f21f7783f934
files NEWS OrthancServer/Scheduler/CallSystemCommand.cpp OrthancServer/Scheduler/DeleteInstanceCommand.cpp OrthancServer/Scheduler/ModifyInstanceCommand.cpp OrthancServer/Scheduler/StorePeerCommand.cpp OrthancServer/Scheduler/StoreScuCommand.cpp
diffstat 6 files changed, 84 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue Aug 05 16:18:45 2014 +0200
+++ b/NEWS	Thu Aug 07 10:02:22 2014 +0200
@@ -1,7 +1,8 @@
 Pending changes in the mainline
 ===============================
 
-* Support of the most common text encodings
+* More fault-tolerant commands in Lua scripts
+* Support of the standard text encodings
 * Parameter to set the default encoding for DICOM files without SpecificCharacterSet
 * Fix of issue #14 (support of XCode 5.1)
 * Upgrade to Google Test 1.7.0
--- a/OrthancServer/Scheduler/CallSystemCommand.cpp	Tue Aug 05 16:18:45 2014 +0200
+++ b/OrthancServer/Scheduler/CallSystemCommand.cpp	Thu Aug 07 10:02:22 2014 +0200
@@ -55,16 +55,27 @@
     {
       LOG(INFO) << "Calling system command " << command_ << " on instance " << *it;
 
-      std::string dicom;
-      context_.ReadFile(dicom, *it, FileContentType_Dicom);
+      try
+      {
+        std::string dicom;
+        context_.ReadFile(dicom, *it, FileContentType_Dicom);
+
+        Toolbox::TemporaryFile tmp;
+        tmp.Write(dicom);
+
+        std::vector<std::string> args = arguments_;
+        args.push_back(tmp.GetPath());
 
-      Toolbox::TemporaryFile tmp;
-      tmp.Write(dicom);
+        Toolbox::ExecuteSystemCommand(command_, args);
 
-      std::vector<std::string> args = arguments_;
-      args.push_back(tmp.GetPath());
-
-      Toolbox::ExecuteSystemCommand(command_, args);
+        // Only chain with other commands if this command succeeds
+        outputs.push_back(*it);
+      }
+      catch (OrthancException& e)
+      {
+        LOG(ERROR) << "Unable to call system command " << command_ 
+                   << " on instance " << *it << " in a Lua script: " << e.What();
+      }
     }
 
     return true;
--- a/OrthancServer/Scheduler/DeleteInstanceCommand.cpp	Tue Aug 05 16:18:45 2014 +0200
+++ b/OrthancServer/Scheduler/DeleteInstanceCommand.cpp	Thu Aug 07 10:02:22 2014 +0200
@@ -44,8 +44,15 @@
     {
       LOG(INFO) << "Deleting instance " << *it;
 
-      Json::Value tmp;
-      context_.GetIndex().DeleteResource(tmp, *it, ResourceType_Instance);
+      try
+      {
+        Json::Value tmp;
+        context_.GetIndex().DeleteResource(tmp, *it, ResourceType_Instance);
+      }
+      catch (OrthancException& e)
+      {
+        LOG(ERROR) << "Unable to delete instance " << *it << " in a Lua script: " << e.What();
+      }
     }
 
     return true;
--- a/OrthancServer/Scheduler/ModifyInstanceCommand.cpp	Tue Aug 05 16:18:45 2014 +0200
+++ b/OrthancServer/Scheduler/ModifyInstanceCommand.cpp	Thu Aug 07 10:02:22 2014 +0200
@@ -44,24 +44,32 @@
     {
       LOG(INFO) << "Modifying resource " << *it;
 
-      std::auto_ptr<ParsedDicomFile> modified;
-
+      try
       {
-        ServerContext::DicomCacheLocker lock(context_, *it);
-        modified.reset(lock.GetDicom().Clone());
-      }
+        std::auto_ptr<ParsedDicomFile> modified;
 
-      modification_.Apply(*modified);
+        {
+          ServerContext::DicomCacheLocker lock(context_, *it);
+          modified.reset(lock.GetDicom().Clone());
+        }
+
+        modification_.Apply(*modified);
 
-      DicomInstanceToStore toStore;
-      toStore.SetParsedDicomFile(*modified);
-      // TODO other metadata
-      toStore.AddMetadata(ResourceType_Instance, MetadataType_ModifiedFrom, *it);
+        DicomInstanceToStore toStore;
+        toStore.SetParsedDicomFile(*modified);
+        // TODO other metadata
+        toStore.AddMetadata(ResourceType_Instance, MetadataType_ModifiedFrom, *it);
+
+        std::string modifiedId;
+        context_.Store(modifiedId, toStore);
 
-      std::string modifiedId;
-      context_.Store(modifiedId, toStore);
-
-      outputs.push_back(modifiedId);
+        // Only chain with other commands if this command succeeds
+        outputs.push_back(modifiedId);
+      }
+      catch (OrthancException& e)
+      {
+        LOG(ERROR) << "Unable to modify instance " << *it << " in a Lua script: " << e.What();
+      }
     }
 
     return true;
--- a/OrthancServer/Scheduler/StorePeerCommand.cpp	Tue Aug 05 16:18:45 2014 +0200
+++ b/OrthancServer/Scheduler/StorePeerCommand.cpp	Thu Aug 07 10:02:22 2014 +0200
@@ -66,16 +66,25 @@
       LOG(INFO) << "Sending resource " << *it << " to peer \"" 
                 << peer_.GetUrl() << "\"";
 
-      context_.ReadFile(client.AccessPostData(), *it, FileContentType_Dicom);
-
-      std::string answer;
-      if (!client.Apply(answer))
+      try
       {
-        LOG(ERROR) << "Unable to send resource " << *it << " to peer \"" << peer_.GetUrl() << "\"";
-        throw OrthancException(ErrorCode_NetworkProtocol);
+        context_.ReadFile(client.AccessPostData(), *it, FileContentType_Dicom);
+
+        std::string answer;
+        if (!client.Apply(answer))
+        {
+          LOG(ERROR) << "Unable to send resource " << *it << " to peer \"" << peer_.GetUrl() << "\"";
+          throw OrthancException(ErrorCode_NetworkProtocol);
+        }
+
+        // Only chain with other commands if this command succeeds
+        outputs.push_back(*it);
       }
-
-      outputs.push_back(*it);
+      catch (OrthancException& e)
+      {
+        LOG(ERROR) << "Unable to forward to an Orthanc peer in a Lua script (instance " 
+                   << *it << ", peer " << peer_.GetUrl() << "): " << e.What();
+      }
     }
 
     return true;
--- a/OrthancServer/Scheduler/StoreScuCommand.cpp	Tue Aug 05 16:18:45 2014 +0200
+++ b/OrthancServer/Scheduler/StoreScuCommand.cpp	Thu Aug 07 10:02:22 2014 +0200
@@ -54,11 +54,22 @@
       LOG(INFO) << "Sending resource " << *it << " to modality \"" 
                 << modality_.GetApplicationEntityTitle() << "\"";
 
-      std::string dicom;
-      context_.ReadFile(dicom, *it, FileContentType_Dicom);
-      locker.GetConnection().Store(dicom);
+      try
+      {
+        std::string dicom;
+        context_.ReadFile(dicom, *it, FileContentType_Dicom);
+        locker.GetConnection().Store(dicom);
 
-      outputs.push_back(*it);
+        // Only chain with other commands if this command succeeds
+        outputs.push_back(*it);
+      }
+      catch (OrthancException& e)
+      {
+        // Ignore transmission errors (e.g. if the remote modality is
+        // powered off)
+        LOG(ERROR) << "Unable to forward to a modality in a Lua script (instance " 
+                   << *it << "): " << e.What();
+      }
     }
 
     return true;