# HG changeset patch # User Sebastien Jodogne # Date 1528725445 -7200 # Node ID 3efc44fac20948b5f0eec98af3da0bc468a05c10 # Parent 06c0a6b8a8715741bf7b56bd0931b3ade334a53e periodically saving jobs diff -r 06c0a6b8a871 -r 3efc44fac209 OrthancServer/ServerContext.cpp --- 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! diff -r 06c0a6b8a871 -r 3efc44fac209 OrthancServer/ServerContext.h --- 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_;