comparison OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp @ 5223:a47b24f231d0

Fix Housekeeper plugin infinite loop if Orthanc is empty
author Alain Mazy <am@osimis.io>
date Mon, 03 Apr 2023 15:13:58 +0200
parents 0ea402b4d901
children 49477780e25a
comparison
equal deleted inserted replaced
5208:1fa3bfa86f8e 5223:a47b24f231d0
486 pluginStatus_.currentlyProcessingConfiguration = currentDbConfiguration; 486 pluginStatus_.currentlyProcessingConfiguration = currentDbConfiguration;
487 487
488 OrthancPlugins::RestApiGet(changes, "/changes?since=" + boost::lexical_cast<std::string>(pluginStatus_.lastProcessedChange) + "&limit=100", false); 488 OrthancPlugins::RestApiGet(changes, "/changes?since=" + boost::lexical_cast<std::string>(pluginStatus_.lastProcessedChange) + "&limit=100", false);
489 } 489 }
490 490
491 for (Json::ArrayIndex i = 0; i < changes["Changes"].size(); i++) 491 if (changes["Changes"].size() > 0)
492 { 492 {
493 const Json::Value& change = changes["Changes"][i]; 493 for (Json::ArrayIndex i = 0; i < changes["Changes"].size(); i++)
494 int64_t seq = change["Seq"].asInt64(); 494 {
495 495 const Json::Value& change = changes["Changes"][i];
496 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 496 int64_t seq = change["Seq"].asInt64();
497 { 497
498 Json::Value result; 498 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
499 Json::Value request; 499 {
500 if (needsReingest) 500 Json::Value result;
501 { 501 Json::Value request;
502 request["ReconstructFiles"] = true; 502 if (needsReingest)
503 } 503 {
504 OrthancPlugins::RestApiPost(result, "/studies/" + change["ID"].asString() + "/reconstruct", request, false); 504 request["ReconstructFiles"] = true;
505 } 505 }
506 506 OrthancPlugins::RestApiPost(result, "/studies/" + change["ID"].asString() + "/reconstruct", request, false);
507 }
508
509 {
510 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_);
511
512 pluginStatus_.lastProcessedChange = seq;
513
514 if (seq >= pluginStatus_.lastChangeToProcess) // we are done !
515 {
516 return true;
517 }
518 }
519
520 if (change["ChangeType"] == "NewStudy")
521 {
522 boost::this_thread::sleep(boost::posix_time::milliseconds(throttleDelay_ * 1000));
523 }
524 }
525 }
526 else
527 {
528 // if the change list is empty and Done is true, it means that there is nothing to process anymore
529 if (changes["Done"].asBool())
507 { 530 {
508 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); 531 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_);
509 532
510 pluginStatus_.lastProcessedChange = seq; 533 pluginStatus_.lastProcessedChange = changes["Last"].asInt64();
511 534
512 if (seq >= pluginStatus_.lastChangeToProcess) // we are done ! 535 return true;
513 {
514 return true;
515 }
516 }
517
518 if (change["ChangeType"] == "NewStudy")
519 {
520 boost::this_thread::sleep(boost::posix_time::milliseconds(throttleDelay_ * 1000));
521 } 536 }
522 } 537 }
523 538
524 return false; 539 return false;
525 } 540 }