# HG changeset patch # User Sebastien Jodogne # Date 1407398542 -7200 # Node ID 060e8918d7a4e78b8ee8d4632ddf6e891eff6002 # Parent 50c889af583bfcf01c7057672f2f593b729106a3 More fault-tolerant commands in Lua scripts diff -r 50c889af583b -r 060e8918d7a4 NEWS --- 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 diff -r 50c889af583b -r 060e8918d7a4 OrthancServer/Scheduler/CallSystemCommand.cpp --- 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 args = arguments_; + args.push_back(tmp.GetPath()); - Toolbox::TemporaryFile tmp; - tmp.Write(dicom); + Toolbox::ExecuteSystemCommand(command_, args); - std::vector 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; diff -r 50c889af583b -r 060e8918d7a4 OrthancServer/Scheduler/DeleteInstanceCommand.cpp --- 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; diff -r 50c889af583b -r 060e8918d7a4 OrthancServer/Scheduler/ModifyInstanceCommand.cpp --- 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 modified; - + try { - ServerContext::DicomCacheLocker lock(context_, *it); - modified.reset(lock.GetDicom().Clone()); - } + std::auto_ptr 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; diff -r 50c889af583b -r 060e8918d7a4 OrthancServer/Scheduler/StorePeerCommand.cpp --- 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; diff -r 50c889af583b -r 060e8918d7a4 OrthancServer/Scheduler/StoreScuCommand.cpp --- 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;