Mercurial > hg > orthanc
changeset 2672:3efc44fac209 jobs
periodically saving jobs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 11 Jun 2018 15:57:25 +0200 |
parents | 06c0a6b8a871 |
children | 8e0bc055d18c |
files | OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h |
diffstat | 2 files changed, 32 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/ServerContext.cpp Mon Jun 11 09:20:04 2018 +0200 +++ b/OrthancServer/ServerContext.cpp Mon Jun 11 15:57:25 2018 +0200 @@ -108,6 +108,28 @@ } + void ServerContext::SaveJobsThread(ServerContext* that, + unsigned int sleepDelay) + { + static const boost::posix_time::time_duration PERIODICITY = + boost::posix_time::seconds(10); + + boost::posix_time::ptime next = + boost::posix_time::microsec_clock::universal_time() + PERIODICITY; + + while (!that->done_) + { + boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay)); + + if (boost::posix_time::microsec_clock::universal_time() >= next) + { + that->SaveJobsEngine(); + next = boost::posix_time::microsec_clock::universal_time() + PERIODICITY; + } + } + } + + void ServerContext::SetupJobsEngine(bool unitTesting, bool loadJobsFromDatabase) { @@ -192,6 +214,7 @@ SetupJobsEngine(unitTesting, loadJobsFromDatabase); changeThread_ = boost::thread(ChangeThread, this, (unitTesting ? 20 : 100)); + saveJobsThread_ = boost::thread(SaveJobsThread, this, (unitTesting ? 20 : 100)); } @@ -222,6 +245,11 @@ changeThread_.join(); } + if (saveJobsThread_.joinable()) + { + saveJobsThread_.join(); + } + SaveJobsEngine(); // Do not change the order below!
--- a/OrthancServer/ServerContext.h Mon Jun 11 09:20:04 2018 +0200 +++ b/OrthancServer/ServerContext.h Mon Jun 11 15:57:25 2018 +0200 @@ -107,6 +107,9 @@ static void ChangeThread(ServerContext* that, unsigned int sleepDelay); + static void SaveJobsThread(ServerContext* that, + unsigned int sleepDelay); + void ReadDicomAsJsonInternal(std::string& result, const std::string& instancePublicId); @@ -138,6 +141,7 @@ bool done_; SharedMessageQueue pendingChanges_; boost::thread changeThread_; + boost::thread saveJobsThread_; SharedArchive queryRetrieveArchive_; std::string defaultLocalAet_;