Mercurial > hg > orthanc
comparison OrthancServer/ServerContext.cpp @ 2673:8e0bc055d18c jobs
JobsRegistry::IObserver
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 11 Jun 2018 16:29:33 +0200 |
parents | 3efc44fac209 |
children | 3fc310ceb6d4 |
comparison
equal
deleted
inserted
replaced
2672:3efc44fac209 | 2673:8e0bc055d18c |
---|---|
119 | 119 |
120 while (!that->done_) | 120 while (!that->done_) |
121 { | 121 { |
122 boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay)); | 122 boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay)); |
123 | 123 |
124 if (boost::posix_time::microsec_clock::universal_time() >= next) | 124 if (that->haveJobsChanged_ || |
125 { | 125 boost::posix_time::microsec_clock::universal_time() >= next) |
126 that->SaveJobsEngine(); | 126 { |
127 that->haveJobsChanged_ = false; | |
128 that->SaveJobsEngine(); | |
127 next = boost::posix_time::microsec_clock::universal_time() + PERIODICITY; | 129 next = boost::posix_time::microsec_clock::universal_time() + PERIODICITY; |
128 } | 130 } |
129 } | 131 } |
130 } | 132 } |
131 | |
132 | 133 |
134 | |
135 void ServerContext::SignalJobSubmitted(const std::string& jobId) | |
136 { | |
137 haveJobsChanged_ = true; | |
138 | |
139 // TODO: Call Lua | |
140 } | |
141 | |
142 | |
143 void ServerContext::SignalJobSuccess(const std::string& jobId) | |
144 { | |
145 haveJobsChanged_ = true; | |
146 | |
147 // TODO: Call Lua | |
148 } | |
149 | |
150 | |
151 void ServerContext::SignalJobFailure(const std::string& jobId) | |
152 { | |
153 haveJobsChanged_ = true; | |
154 | |
155 // TODO: Call Lua | |
156 } | |
157 | |
158 | |
133 void ServerContext::SetupJobsEngine(bool unitTesting, | 159 void ServerContext::SetupJobsEngine(bool unitTesting, |
134 bool loadJobsFromDatabase) | 160 bool loadJobsFromDatabase) |
135 { | 161 { |
136 jobsEngine_.SetWorkersCount(Configuration::GetGlobalUnsignedIntegerParameter("ConcurrentJobs", 2)); | 162 jobsEngine_.SetWorkersCount(Configuration::GetGlobalUnsignedIntegerParameter("ConcurrentJobs", 2)); |
137 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200); | 163 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200); |
164 LOG(WARNING) << "Not reloading the jobs from the last execution of Orthanc"; | 190 LOG(WARNING) << "Not reloading the jobs from the last execution of Orthanc"; |
165 } | 191 } |
166 | 192 |
167 //jobsEngine_.GetRegistry().SetMaxCompleted // TODO | 193 //jobsEngine_.GetRegistry().SetMaxCompleted // TODO |
168 | 194 |
195 jobsEngine_.GetRegistry().SetObserver(*this); | |
169 jobsEngine_.Start(); | 196 jobsEngine_.Start(); |
170 } | 197 } |
171 | 198 |
172 | 199 |
173 void ServerContext::SaveJobsEngine() | 200 void ServerContext::SaveJobsEngine() |
204 lua_(*this), | 231 lua_(*this), |
205 #if ORTHANC_ENABLE_PLUGINS == 1 | 232 #if ORTHANC_ENABLE_PLUGINS == 1 |
206 plugins_(NULL), | 233 plugins_(NULL), |
207 #endif | 234 #endif |
208 done_(false), | 235 done_(false), |
236 haveJobsChanged_(false), | |
209 queryRetrieveArchive_(Configuration::GetGlobalUnsignedIntegerParameter("QueryRetrieveSize", 10)), | 237 queryRetrieveArchive_(Configuration::GetGlobalUnsignedIntegerParameter("QueryRetrieveSize", 10)), |
210 defaultLocalAet_(Configuration::GetGlobalStringParameter("DicomAet", "ORTHANC")) | 238 defaultLocalAet_(Configuration::GetGlobalStringParameter("DicomAet", "ORTHANC")) |
211 { | 239 { |
212 listeners_.push_back(ServerListener(lua_, "Lua")); | 240 listeners_.push_back(ServerListener(lua_, "Lua")); |
213 | 241 |
248 if (saveJobsThread_.joinable()) | 276 if (saveJobsThread_.joinable()) |
249 { | 277 { |
250 saveJobsThread_.join(); | 278 saveJobsThread_.join(); |
251 } | 279 } |
252 | 280 |
281 jobsEngine_.GetRegistry().ResetObserver(); | |
253 SaveJobsEngine(); | 282 SaveJobsEngine(); |
254 | 283 |
255 // Do not change the order below! | 284 // Do not change the order below! |
256 jobsEngine_.Stop(); | 285 jobsEngine_.Stop(); |
257 index_.Stop(); | 286 index_.Stop(); |