Mercurial > hg > orthanc
comparison Core/JobsEngine/JobsRegistry.cpp @ 3240:e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 15 Feb 2019 17:26:45 +0100 |
parents | 20826867141f |
children | fe73717105b6 |
comparison
equal
deleted
inserted
replaced
3239:407e1a188105 | 3240:e44e0127e553 |
---|---|
108 } | 108 } |
109 | 109 |
110 job->GetJobType(jobType_); | 110 job->GetJobType(jobType_); |
111 job->Start(); | 111 job->Start(); |
112 | 112 |
113 lastStatus_ = JobStatus(ErrorCode_Success, *job_); | 113 lastStatus_ = JobStatus(ErrorCode_Success, "", *job_); |
114 } | 114 } |
115 | 115 |
116 const std::string& GetId() const | 116 const std::string& GetId() const |
117 { | 117 { |
118 return id_; | 118 return id_; |
316 | 316 |
317 job_.reset(unserializer.UnserializeJob(serialized[JOB])); | 317 job_.reset(unserializer.UnserializeJob(serialized[JOB])); |
318 job_->GetJobType(jobType_); | 318 job_->GetJobType(jobType_); |
319 job_->Start(); | 319 job_->Start(); |
320 | 320 |
321 lastStatus_ = JobStatus(ErrorCode_Success, *job_); | 321 lastStatus_ = JobStatus(ErrorCode_Success, "", *job_); |
322 } | 322 } |
323 }; | 323 }; |
324 | 324 |
325 | 325 |
326 bool JobsRegistry::PriorityComparator::operator() (JobHandler*& a, | 326 bool JobsRegistry::PriorityComparator::operator() (JobHandler*& a, |
737 std::string id; | 737 std::string id; |
738 SubmitInternal(id, new JobHandler(job, priority)); | 738 SubmitInternal(id, new JobHandler(job, priority)); |
739 } | 739 } |
740 | 740 |
741 | 741 |
742 bool JobsRegistry::SubmitAndWait(Json::Value& successContent, | 742 void JobsRegistry::SubmitAndWait(Json::Value& successContent, |
743 IJob* job, // Takes ownership | 743 IJob* job, // Takes ownership |
744 int priority) | 744 int priority) |
745 { | 745 { |
746 std::string id; | 746 std::string id; |
747 Submit(id, job, priority); | 747 Submit(id, job, priority); |
762 "make sure that \"JobsHistorySize\" is not 0"); | 762 "make sure that \"JobsHistorySize\" is not 0"); |
763 } | 763 } |
764 else if (state == JobState_Failure) | 764 else if (state == JobState_Failure) |
765 { | 765 { |
766 // Failure | 766 // Failure |
767 break; | 767 JobsIndex::const_iterator it = jobsIndex_.find(id); |
768 if (it != jobsIndex_.end()) // Should always be true, already tested in GetStateInternal() | |
769 { | |
770 ErrorCode code = it->second->GetLastStatus().GetErrorCode(); | |
771 const std::string& details = it->second->GetLastStatus().GetDetails(); | |
772 | |
773 if (details.empty()) | |
774 { | |
775 throw OrthancException(code); | |
776 } | |
777 else | |
778 { | |
779 throw OrthancException(code, details); | |
780 } | |
781 } | |
782 else | |
783 { | |
784 throw OrthancException(ErrorCode_InternalError); | |
785 } | |
768 } | 786 } |
769 else if (state == JobState_Success) | 787 else if (state == JobState_Success) |
770 { | 788 { |
771 // Success, try and retrieve the status of the job | 789 // Success, try and retrieve the status of the job |
772 JobsIndex::const_iterator it = jobsIndex_.find(id); | 790 JobsIndex::const_iterator it = jobsIndex_.find(id); |
779 { | 797 { |
780 const JobStatus& status = it->second->GetLastStatus(); | 798 const JobStatus& status = it->second->GetLastStatus(); |
781 successContent = status.GetPublicContent(); | 799 successContent = status.GetPublicContent(); |
782 } | 800 } |
783 | 801 |
784 break; | 802 return; |
785 } | 803 } |
786 else | 804 else |
787 { | 805 { |
788 // This job has not finished yet, wait for new completion | 806 // This job has not finished yet, wait for new completion |
789 someJobComplete_.wait(lock); | 807 someJobComplete_.wait(lock); |
790 } | 808 } |
791 } | 809 } |
792 } | 810 } |
793 | |
794 return (state == JobState_Success); | |
795 } | 811 } |
796 | 812 |
797 | 813 |
798 bool JobsRegistry::SetPriority(const std::string& id, | 814 bool JobsRegistry::SetPriority(const std::string& id, |
799 int priority) | 815 int priority) |
1318 targetRetryTimeout_ = timeout; | 1334 targetRetryTimeout_ = timeout; |
1319 } | 1335 } |
1320 } | 1336 } |
1321 | 1337 |
1322 | 1338 |
1323 void JobsRegistry::RunningJob::UpdateStatus(ErrorCode code) | 1339 void JobsRegistry::RunningJob::UpdateStatus(ErrorCode code, |
1340 const std::string& details) | |
1324 { | 1341 { |
1325 if (!IsValid()) | 1342 if (!IsValid()) |
1326 { | 1343 { |
1327 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 1344 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
1328 } | 1345 } |
1329 else | 1346 else |
1330 { | 1347 { |
1331 JobStatus status(code, *job_); | 1348 JobStatus status(code, details, *job_); |
1332 | 1349 |
1333 boost::mutex::scoped_lock lock(registry_.mutex_); | 1350 boost::mutex::scoped_lock lock(registry_.mutex_); |
1334 registry_.CheckInvariants(); | 1351 registry_.CheckInvariants(); |
1335 assert(handler_->GetState() == JobState_Running); | 1352 assert(handler_->GetState() == JobState_Running); |
1336 | 1353 |