Mercurial > hg > orthanc
comparison OrthancServer/ServerContext.cpp @ 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 |
comparison
equal
deleted
inserted
replaced
2671:06c0a6b8a871 | 2672:3efc44fac209 |
---|---|
106 } | 106 } |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 | 110 |
111 void ServerContext::SaveJobsThread(ServerContext* that, | |
112 unsigned int sleepDelay) | |
113 { | |
114 static const boost::posix_time::time_duration PERIODICITY = | |
115 boost::posix_time::seconds(10); | |
116 | |
117 boost::posix_time::ptime next = | |
118 boost::posix_time::microsec_clock::universal_time() + PERIODICITY; | |
119 | |
120 while (!that->done_) | |
121 { | |
122 boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay)); | |
123 | |
124 if (boost::posix_time::microsec_clock::universal_time() >= next) | |
125 { | |
126 that->SaveJobsEngine(); | |
127 next = boost::posix_time::microsec_clock::universal_time() + PERIODICITY; | |
128 } | |
129 } | |
130 } | |
131 | |
132 | |
111 void ServerContext::SetupJobsEngine(bool unitTesting, | 133 void ServerContext::SetupJobsEngine(bool unitTesting, |
112 bool loadJobsFromDatabase) | 134 bool loadJobsFromDatabase) |
113 { | 135 { |
114 jobsEngine_.SetWorkersCount(Configuration::GetGlobalUnsignedIntegerParameter("ConcurrentJobs", 2)); | 136 jobsEngine_.SetWorkersCount(Configuration::GetGlobalUnsignedIntegerParameter("ConcurrentJobs", 2)); |
115 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200); | 137 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200); |
190 listeners_.push_back(ServerListener(lua_, "Lua")); | 212 listeners_.push_back(ServerListener(lua_, "Lua")); |
191 | 213 |
192 SetupJobsEngine(unitTesting, loadJobsFromDatabase); | 214 SetupJobsEngine(unitTesting, loadJobsFromDatabase); |
193 | 215 |
194 changeThread_ = boost::thread(ChangeThread, this, (unitTesting ? 20 : 100)); | 216 changeThread_ = boost::thread(ChangeThread, this, (unitTesting ? 20 : 100)); |
217 saveJobsThread_ = boost::thread(SaveJobsThread, this, (unitTesting ? 20 : 100)); | |
195 } | 218 } |
196 | 219 |
197 | 220 |
198 | 221 |
199 ServerContext::~ServerContext() | 222 ServerContext::~ServerContext() |
218 done_ = true; | 241 done_ = true; |
219 | 242 |
220 if (changeThread_.joinable()) | 243 if (changeThread_.joinable()) |
221 { | 244 { |
222 changeThread_.join(); | 245 changeThread_.join(); |
246 } | |
247 | |
248 if (saveJobsThread_.joinable()) | |
249 { | |
250 saveJobsThread_.join(); | |
223 } | 251 } |
224 | 252 |
225 SaveJobsEngine(); | 253 SaveJobsEngine(); |
226 | 254 |
227 // Do not change the order below! | 255 // Do not change the order below! |