Mercurial > hg > orthanc
changeset 7145:a9a0d0455dce
added JobsEngine::SetThreadNames()
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Wed, 09 Sep 2026 09:25:46 +0200 |
| parents | a2cd12438c41 |
| children | 0dd4240ea372 |
| files | OrthancFramework/Sources/JobsEngine/JobsEngine.cpp OrthancFramework/Sources/JobsEngine/JobsEngine.h |
| diffstat | 2 files changed, 38 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Sources/JobsEngine/JobsEngine.cpp Mon Aug 31 09:16:01 2026 +0200 +++ b/OrthancFramework/Sources/JobsEngine/JobsEngine.cpp Wed Sep 09 09:25:46 2026 +0200 @@ -107,9 +107,10 @@ } - void JobsEngine::RetryHandler(JobsEngine* engine) + void JobsEngine::RetryHandler(JobsEngine* engine, + std::string threadName) { - Logging::ScopedCurrentThreadNameSetter setter("JOBS-RETRY"); + Logging::ScopedCurrentThreadNameSetter setter(threadName); assert(engine != NULL); @@ -122,10 +123,11 @@ void JobsEngine::Worker(JobsEngine* engine, - size_t workerIndex) + size_t workerIndex, + std::string threadNamePrefix) { assert(engine != NULL); - Logging::ScopedCurrentThreadNameSetter setter(std::string("JOBS-WORKER-") + boost::lexical_cast<std::string>(workerIndex)); + Logging::ScopedCurrentThreadNameSetter setter(threadNamePrefix + "-" + boost::lexical_cast<std::string>(workerIndex)); CLOG(INFO, JOBS) << "Worker thread " << workerIndex << " has started"; while (engine->IsRunning()) @@ -158,7 +160,9 @@ state_(State_Setup), registry_(new JobsRegistry(maxCompletedJobs)), threadSleep_(200), - workers_(1) + workers_(1), + loggingRetryThreadName_("JOBS-RETRY"), + loggingWorkerThreadPrefix_("JOBS-WORKER") { } @@ -261,14 +265,14 @@ throw OrthancException(ErrorCode_BadSequenceOfCalls); } - retryHandler_ = boost::thread(RetryHandler, this); + retryHandler_ = boost::thread(RetryHandler, this, loggingRetryThreadName_); assert(!workers_.empty()); for (size_t i = 0; i < workers_.size(); i++) { assert(workers_[i] == NULL); - workers_[i] = new boost::thread(Worker, this, i); + workers_[i] = new boost::thread(Worker, this, i, loggingWorkerThreadPrefix_); } state_ = State_Running; @@ -316,4 +320,22 @@ CLOG(WARNING, JOBS) << "The jobs engine has stopped"; } + + + void JobsEngine::SetThreadNames(const std::string& retryThreadName, + const std::string& workerThreadPrefix) + { + boost::mutex::scoped_lock lock(stateMutex_); + + if (state_ != State_Setup) + { + // Can only be invoked before calling "Start()" + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + else + { + loggingRetryThreadName_ = retryThreadName; + loggingWorkerThreadPrefix_ = workerThreadPrefix; + } + } }
--- a/OrthancFramework/Sources/JobsEngine/JobsEngine.h Mon Aug 31 09:16:01 2026 +0200 +++ b/OrthancFramework/Sources/JobsEngine/JobsEngine.h Wed Sep 09 09:25:46 2026 +0200 @@ -49,16 +49,20 @@ boost::thread retryHandler_; unsigned int threadSleep_; std::vector<boost::thread*> workers_; + std::string loggingRetryThreadName_; + std::string loggingWorkerThreadPrefix_; bool IsRunning(); bool ExecuteStep(JobsRegistry::RunningJob& running, size_t workerIndex); - static void RetryHandler(JobsEngine* engine); + static void RetryHandler(JobsEngine* engine, + std::string threadName); static void Worker(JobsEngine* engine, - size_t workerIndex); + size_t workerIndex, + std::string threadNamePrefix); public: explicit JobsEngine(size_t maxCompletedJobs); @@ -80,5 +84,8 @@ void Start(); void Stop(); + + void SetThreadNames(const std::string& retryThreadName, + const std::string& workerThreadPrefix); }; }
