Mercurial > hg > orthanc
changeset 5145:df040c83796c
correctly report ThreadedSetOfInstancesJob progress
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 27 Jan 2023 11:23:35 +0100 |
parents | 9fc5bf6f3c75 |
children | 4a0dfa23d28c |
files | OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.h |
diffstat | 2 files changed, 26 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp Thu Jan 26 16:31:11 2023 +0100 +++ b/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp Fri Jan 27 11:23:35 2023 +0100 @@ -43,7 +43,7 @@ started_(false), stopRequested_(false), permissive_(false), - currentStep_(ThreadedJobStep_ProcessingInstances), + currentStep_(ThreadedJobStep_NotStarted), workersCount_(workersCount), context_(context), keepSource_(keepSource), @@ -98,6 +98,7 @@ { boost::recursive_mutex::scoped_lock lock(mutex_); + instancesToProcessQueue_.Clear(); stopRequested_ = true; } @@ -139,7 +140,7 @@ try { - if (currentStep_ == ThreadedJobStep_ProcessingInstances) + if (currentStep_ == ThreadedJobStep_NotStarted) { // create the workers and enqueue all instances for (std::set<std::string>::const_iterator it = instancesToProcess_.begin(); it != instancesToProcess_.end(); ++it) @@ -148,18 +149,29 @@ } InitWorkers(workersCount_); + currentStep_ = ThreadedJobStep_ProcessingInstances; + } + else if (currentStep_ == ThreadedJobStep_ProcessingInstances) + { // wait until all instances are processed by the workers - WaitWorkersComplete(); + if (instancesToProcessQueue_.GetSize() != 0) + { + return JobStepResult::Continue(); + } + else + { + WaitWorkersComplete(); - // check job has really completed !!! it might have been interrupted because of an error - if ((processedInstances_.size() != instancesToProcess_.size()) - || (!IsPermissive() && failedInstances_.size() > 0)) - { - return JobStepResult::Failure(GetErrorCode(), NULL); + // check job has really completed !!! it might have been interrupted because of an error + if ((processedInstances_.size() != instancesToProcess_.size()) + || (!IsPermissive() && failedInstances_.size() > 0)) + { + return JobStepResult::Failure(GetErrorCode(), NULL); + } + + currentStep_ = ThreadedJobStep_PostProcessingInstances; + return JobStepResult::Continue(); } - - currentStep_ = ThreadedJobStep_PostProcessingInstances; - return JobStepResult::Continue(); } else if (currentStep_ == ThreadedJobStep_PostProcessingInstances) { @@ -338,7 +350,7 @@ if (started_) { // TODO: cleanup the instances that have been generated during the previous run - currentStep_ = ThreadedJobStep_ProcessingInstances; + currentStep_ = ThreadedJobStep_NotStarted; stopRequested_ = false; processedInstances_.clear(); failedInstances_.clear(); @@ -411,7 +423,7 @@ started_(false), stopRequested_(false), permissive_(false), - currentStep_(ThreadedJobStep_ProcessingInstances), + currentStep_(ThreadedJobStep_NotStarted), workersCount_(1), context_(context), keepSource_(defaultKeepSource),
--- a/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.h Thu Jan 26 16:31:11 2023 +0100 +++ b/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.h Fri Jan 27 11:23:35 2023 +0100 @@ -41,6 +41,7 @@ public: enum ThreadedJobStep // cannot use "Step" since there is a method with this name ! { + ThreadedJobStep_NotStarted, ThreadedJobStep_ProcessingInstances, ThreadedJobStep_PostProcessingInstances, ThreadedJobStep_Cleanup,