# HG changeset patch # User Alain Mazy # Date 1674815015 -3600 # Node ID df040c83796cbb2eaed7fd1c9225d5967f0955ae # Parent 9fc5bf6f3c7555c4eda903a65150d08c5adca41e correctly report ThreadedSetOfInstancesJob progress diff -r 9fc5bf6f3c75 -r df040c83796c OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp --- 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::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), diff -r 9fc5bf6f3c75 -r df040c83796c OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.h --- 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,