comparison OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp @ 5364:b5f2122a1334

Added a route to delete completed jobs from history: DELETE /jobs/{id}
author Alain Mazy <am@osimis.io>
date Thu, 20 Jul 2023 10:51:34 +0200
parents b5c502bcaf99
children 48b8dae6dc77
comparison
equal deleted inserted replaced
5362:78aad3916da4 5364:b5f2122a1334
643 handler.GetLastStatus(), 643 handler.GetLastStatus(),
644 handler.GetCreationTime(), 644 handler.GetCreationTime(),
645 handler.GetLastStateChangeTime(), 645 handler.GetLastStateChangeTime(),
646 handler.GetRuntime()); 646 handler.GetRuntime());
647 return true; 647 return true;
648 }
649 }
650
651
652 bool JobsRegistry::DeleteJobInfo(const std::string& id)
653 {
654 LOG(INFO) << "Deleting job: " << id;
655
656 boost::mutex::scoped_lock lock(mutex_);
657 CheckInvariants();
658
659 JobsIndex::iterator found = jobsIndex_.find(id);
660
661 if (found == jobsIndex_.end())
662 {
663 LOG(WARNING) << "Unknown job to delete: " << id;
664 return false;
665 }
666 else
667 {
668 for (CompletedJobs::iterator it = completedJobs_.begin();
669 it != completedJobs_.end(); ++it)
670 {
671 if (*it == found->second)
672 {
673 found->second->GetJob().DeleteAllOutputs();
674 delete found->second;
675
676 completedJobs_.erase(it);
677 jobsIndex_.erase(id);
678 return true;
679 }
680 }
681
682 LOG(WARNING) << "Can not delete a job that is not complete: " << id;
683 return false;
648 } 684 }
649 } 685 }
650 686
651 687
652 bool JobsRegistry::GetJobOutput(std::string& output, 688 bool JobsRegistry::GetJobOutput(std::string& output,