Mercurial > hg > orthanc
diff Core/JobsEngine/JobsRegistry.cpp @ 2570:2e879c796ec7 jobs
JobsRegistry::SubmitAndWait(), StoreScuJob
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 07 May 2018 21:42:04 +0200 |
parents | 2af17cd5eb1f |
children | 3372c5255333 |
line wrap: on
line diff
--- a/Core/JobsEngine/JobsRegistry.cpp Mon May 07 15:37:20 2018 +0200 +++ b/Core/JobsEngine/JobsRegistry.cpp Mon May 07 21:42:04 2018 +0200 @@ -92,6 +92,7 @@ } lastStatus_ = JobStatus(ErrorCode_Success, *job); + job->Start(); } const std::string& GetId() const @@ -348,6 +349,8 @@ completedJobs_.push_back(&job); ForgetOldCompletedJobs(); + someJobComplete_.notify_all(); + CheckInvariants(); } @@ -382,6 +385,24 @@ } + bool JobsRegistry::GetStateInternal(JobState& state, + const std::string& id) + { + CheckInvariants(); + + JobsIndex::const_iterator it = jobsIndex_.find(id); + if (it == jobsIndex_.end()) + { + return false; + } + else + { + state = it->second->GetState(); + return true; + } + } + + JobsRegistry::~JobsRegistry() { for (JobsIndex::iterator it = jobsIndex_.begin(); it != jobsIndex_.end(); ++it) @@ -474,6 +495,31 @@ } + bool JobsRegistry::SubmitAndWait(IJob* job, // Takes ownership + int priority) + { + std::string id; + Submit(id, job, priority); + + printf(">> %s\n", id.c_str()); fflush(stdout); + + JobState state; + + { + boost::mutex::scoped_lock lock(mutex_); + + while (GetStateInternal(state, id) && + state != JobState_Success && + state != JobState_Failure) + { + someJobComplete_.wait(lock); + } + } + + return (state == JobState_Success); + } + + void JobsRegistry::SetPriority(const std::string& id, int priority) { @@ -687,18 +733,7 @@ const std::string& id) { boost::mutex::scoped_lock lock(mutex_); - CheckInvariants(); - - JobsIndex::const_iterator it = jobsIndex_.find(id); - if (it == jobsIndex_.end()) - { - return false; - } - else - { - state = it->second->GetState(); - return true; - } + return GetStateInternal(state, id); }