Mercurial > hg > orthanc
comparison Core/JobsEngine/JobsRegistry.cpp @ 2867:251614c2edac
DicomMoveScuJob
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Oct 2018 16:08:51 +0200 |
parents | 859a4950d48f |
children | 577786f59252 |
comparison
equal
deleted
inserted
replaced
2866:437e6ba20a5e | 2867:251614c2edac |
---|---|
683 std::string id; | 683 std::string id; |
684 SubmitInternal(id, new JobHandler(job, priority), false); | 684 SubmitInternal(id, new JobHandler(job, priority), false); |
685 } | 685 } |
686 | 686 |
687 | 687 |
688 bool JobsRegistry::SubmitAndWait(IJob* job, // Takes ownership | 688 bool JobsRegistry::SubmitAndWait(Json::Value& successContent, |
689 IJob* job, // Takes ownership | |
689 int priority) | 690 int priority) |
690 { | 691 { |
691 std::string id; | 692 std::string id; |
692 Submit(id, job, priority); | 693 Submit(id, job, priority); |
693 | 694 |
694 JobState state = JobState_Pending; | 695 JobState state = JobState_Pending; // Dummy initialization |
695 | 696 |
696 { | 697 { |
697 boost::mutex::scoped_lock lock(mutex_); | 698 boost::mutex::scoped_lock lock(mutex_); |
698 | 699 |
699 while (GetStateInternal(state, id) && | 700 for (;;) |
700 state != JobState_Success && | 701 { |
701 state != JobState_Failure) | 702 if (!GetStateInternal(state, id)) |
702 { | 703 { |
703 someJobComplete_.wait(lock); | 704 // Job has finished and has been lost (should not happen) |
705 state = JobState_Failure; | |
706 break; | |
707 } | |
708 else if (state == JobState_Failure) | |
709 { | |
710 // Failure | |
711 break; | |
712 } | |
713 else if (state == JobState_Success) | |
714 { | |
715 // Success, try and retrieve the status of the job | |
716 JobsIndex::const_iterator it = jobsIndex_.find(id); | |
717 if (it == jobsIndex_.end()) | |
718 { | |
719 // Should not happen | |
720 state = JobState_Failure; | |
721 } | |
722 else | |
723 { | |
724 const JobStatus& status = it->second->GetLastStatus(); | |
725 successContent = status.GetPublicContent(); | |
726 } | |
727 | |
728 break; | |
729 } | |
730 else | |
731 { | |
732 // This job has not finished yet, wait for new completion | |
733 someJobComplete_.wait(lock); | |
734 } | |
704 } | 735 } |
705 } | 736 } |
706 | 737 |
707 return (state == JobState_Success); | 738 return (state == JobState_Success); |
708 } | 739 } |