# HG changeset patch # User Alain Mazy # Date 1680527638 -7200 # Node ID a47b24f231d0f93f4b05872cb69d79bfd513ebad # Parent 1fa3bfa86f8ed73d50579a3bc4504efcfbbfbd06 Fix Housekeeper plugin infinite loop if Orthanc is empty diff -r 1fa3bfa86f8e -r a47b24f231d0 NEWS --- a/NEWS Fri Mar 31 16:32:02 2023 +0200 +++ b/NEWS Mon Apr 03 15:13:58 2023 +0200 @@ -19,6 +19,7 @@ * Fix issue 214: VOILUTSequence is not returned in Wado-RS * Fix /tools/reset crashing when ExtraMainDicomTags were defined +* Fix Housekeeper plugin infinite loop if Orthanc is empty. Version 1.11.3 (2023-02-03) diff -r 1fa3bfa86f8e -r a47b24f231d0 OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp --- a/OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp Fri Mar 31 16:32:02 2023 +0200 +++ b/OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp Mon Apr 03 15:13:58 2023 +0200 @@ -488,36 +488,51 @@ OrthancPlugins::RestApiGet(changes, "/changes?since=" + boost::lexical_cast(pluginStatus_.lastProcessedChange) + "&limit=100", false); } - for (Json::ArrayIndex i = 0; i < changes["Changes"].size(); i++) + if (changes["Changes"].size() > 0) { - const Json::Value& change = changes["Changes"][i]; - int64_t seq = change["Seq"].asInt64(); - - if (change["ChangeType"] == "NewStudy") // some StableStudy might be missing if orthanc was shutdown during a StableAge -> consider only the NewStudy events that can not be missed + for (Json::ArrayIndex i = 0; i < changes["Changes"].size(); i++) { - Json::Value result; - Json::Value request; - if (needsReingest) + const Json::Value& change = changes["Changes"][i]; + int64_t seq = change["Seq"].asInt64(); + + if (change["ChangeType"] == "NewStudy") // some StableStudy might be missing if orthanc was shutdown during a StableAge -> consider only the NewStudy events that can not be missed + { + Json::Value result; + Json::Value request; + if (needsReingest) + { + request["ReconstructFiles"] = true; + } + OrthancPlugins::RestApiPost(result, "/studies/" + change["ID"].asString() + "/reconstruct", request, false); + } + { - request["ReconstructFiles"] = true; + boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); + + pluginStatus_.lastProcessedChange = seq; + + if (seq >= pluginStatus_.lastChangeToProcess) // we are done ! + { + return true; + } } - OrthancPlugins::RestApiPost(result, "/studies/" + change["ID"].asString() + "/reconstruct", request, false); + + if (change["ChangeType"] == "NewStudy") + { + boost::this_thread::sleep(boost::posix_time::milliseconds(throttleDelay_ * 1000)); + } } - + } + else + { + // if the change list is empty and Done is true, it means that there is nothing to process anymore + if (changes["Done"].asBool()) { boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); - pluginStatus_.lastProcessedChange = seq; + pluginStatus_.lastProcessedChange = changes["Last"].asInt64(); - if (seq >= pluginStatus_.lastChangeToProcess) // we are done ! - { - return true; - } - } - - if (change["ChangeType"] == "NewStudy") - { - boost::this_thread::sleep(boost::posix_time::milliseconds(throttleDelay_ * 1000)); + return true; } }