Mercurial > hg > orthanc
comparison OrthancServer/ServerContext.cpp @ 2815:925d8dc03a23
unserialization of jobs from plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Sep 2018 16:34:21 +0200 |
parents | 37583cd183ed |
children | 8aa6aef11b70 |
comparison
equal
deleted
inserted
replaced
2814:7d1d3136f6cf | 2815:925d8dc03a23 |
---|---|
154 | 154 |
155 | 155 |
156 void ServerContext::SetupJobsEngine(bool unitTesting, | 156 void ServerContext::SetupJobsEngine(bool unitTesting, |
157 bool loadJobsFromDatabase) | 157 bool loadJobsFromDatabase) |
158 { | 158 { |
159 jobsEngine_.SetWorkersCount(Configuration::GetGlobalUnsignedIntegerParameter("ConcurrentJobs", 2)); | |
160 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200); | |
161 | |
162 if (loadJobsFromDatabase) | 159 if (loadJobsFromDatabase) |
163 { | 160 { |
164 std::string serialized; | 161 std::string serialized; |
165 if (index_.LookupGlobalProperty(serialized, GlobalProperty_JobsRegistry)) | 162 if (index_.LookupGlobalProperty(serialized, GlobalProperty_JobsRegistry)) |
166 { | 163 { |
167 LOG(WARNING) << "Reloading the jobs from the last execution of Orthanc"; | 164 LOG(WARNING) << "Reloading the jobs from the last execution of Orthanc"; |
165 OrthancJobUnserializer unserializer(*this); | |
168 | 166 |
169 try | 167 try |
170 { | 168 { |
171 bool plugin = false; | 169 jobsEngine_.LoadRegistryFromString(unserializer, serialized); |
172 | |
173 #if ORTHANC_ENABLE_PLUGINS == 1 | |
174 if (HasPlugins() && | |
175 plugins_->UnserializeJob(serialized)) | |
176 { | |
177 plugin = true; | |
178 } | |
179 #endif | |
180 | |
181 if (!plugin) | |
182 { | |
183 OrthancJobUnserializer unserializer(*this); | |
184 jobsEngine_.LoadRegistryFromString(unserializer, serialized); | |
185 } | |
186 } | 170 } |
187 catch (OrthancException& e) | 171 catch (OrthancException& e) |
188 { | 172 { |
189 LOG(ERROR) << "Cannot unserialize the jobs engine: " << e.What(); | 173 LOG(ERROR) << "Cannot unserialize the jobs engine: " << e.What(); |
190 throw; | 174 throw; |
202 | 186 |
203 //jobsEngine_.GetRegistry().SetMaxCompleted // TODO | 187 //jobsEngine_.GetRegistry().SetMaxCompleted // TODO |
204 | 188 |
205 jobsEngine_.GetRegistry().SetObserver(*this); | 189 jobsEngine_.GetRegistry().SetObserver(*this); |
206 jobsEngine_.Start(); | 190 jobsEngine_.Start(); |
191 isJobsEngineUnserialized_ = true; | |
192 | |
193 saveJobsThread_ = boost::thread(SaveJobsThread, this, (unitTesting ? 20 : 100)); | |
207 } | 194 } |
208 | 195 |
209 | 196 |
210 void ServerContext::SaveJobsEngine() | 197 void ServerContext::SaveJobsEngine() |
211 { | 198 { |
228 } | 215 } |
229 | 216 |
230 | 217 |
231 ServerContext::ServerContext(IDatabaseWrapper& database, | 218 ServerContext::ServerContext(IDatabaseWrapper& database, |
232 IStorageArea& area, | 219 IStorageArea& area, |
233 bool unitTesting, | 220 bool unitTesting) : |
234 bool loadJobsFromDatabase) : | |
235 index_(*this, database, (unitTesting ? 20 : 500)), | 221 index_(*this, database, (unitTesting ? 20 : 500)), |
236 area_(area), | 222 area_(area), |
237 compressionEnabled_(false), | 223 compressionEnabled_(false), |
238 storeMD5_(true), | 224 storeMD5_(true), |
239 provider_(*this), | 225 provider_(*this), |
244 #if ORTHANC_ENABLE_PLUGINS == 1 | 230 #if ORTHANC_ENABLE_PLUGINS == 1 |
245 plugins_(NULL), | 231 plugins_(NULL), |
246 #endif | 232 #endif |
247 done_(false), | 233 done_(false), |
248 haveJobsChanged_(false), | 234 haveJobsChanged_(false), |
235 isJobsEngineUnserialized_(false), | |
249 queryRetrieveArchive_(Configuration::GetGlobalUnsignedIntegerParameter("QueryRetrieveSize", 10)), | 236 queryRetrieveArchive_(Configuration::GetGlobalUnsignedIntegerParameter("QueryRetrieveSize", 10)), |
250 defaultLocalAet_(Configuration::GetGlobalStringParameter("DicomAet", "ORTHANC")) | 237 defaultLocalAet_(Configuration::GetGlobalStringParameter("DicomAet", "ORTHANC")) |
251 { | 238 { |
239 jobsEngine_.SetWorkersCount(Configuration::GetGlobalUnsignedIntegerParameter("ConcurrentJobs", 2)); | |
240 jobsEngine_.SetThreadSleep(unitTesting ? 20 : 200); | |
241 | |
252 listeners_.push_back(ServerListener(luaListener_, "Lua")); | 242 listeners_.push_back(ServerListener(luaListener_, "Lua")); |
253 | |
254 SetupJobsEngine(unitTesting, loadJobsFromDatabase); | |
255 | |
256 changeThread_ = boost::thread(ChangeThread, this, (unitTesting ? 20 : 100)); | 243 changeThread_ = boost::thread(ChangeThread, this, (unitTesting ? 20 : 100)); |
257 saveJobsThread_ = boost::thread(SaveJobsThread, this, (unitTesting ? 20 : 100)); | |
258 } | 244 } |
259 | 245 |
260 | 246 |
261 | 247 |
262 ServerContext::~ServerContext() | 248 ServerContext::~ServerContext() |
289 { | 275 { |
290 saveJobsThread_.join(); | 276 saveJobsThread_.join(); |
291 } | 277 } |
292 | 278 |
293 jobsEngine_.GetRegistry().ResetObserver(); | 279 jobsEngine_.GetRegistry().ResetObserver(); |
294 SaveJobsEngine(); | 280 |
281 if (isJobsEngineUnserialized_) | |
282 { | |
283 // Avoid losing jobs if the JobsRegistry cannot be unserialized | |
284 SaveJobsEngine(); | |
285 } | |
295 | 286 |
296 // Do not change the order below! | 287 // Do not change the order below! |
297 jobsEngine_.Stop(); | 288 jobsEngine_.Stop(); |
298 index_.Stop(); | 289 index_.Stop(); |
299 } | 290 } |