Mercurial > hg > orthanc
comparison Core/JobsEngine/JobsRegistry.cpp @ 2663:228e2783ce83 jobs
some jobs might not be serializable
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 07 Jun 2018 18:18:02 +0200 |
parents | a6d3e45eeff5 |
children | 5fa2f2ce74f0 |
comparison
equal
deleted
inserted
replaced
2662:47d812308d63 | 2663:228e2783ce83 |
---|---|
233 void SetLastErrorCode(ErrorCode code) | 233 void SetLastErrorCode(ErrorCode code) |
234 { | 234 { |
235 lastStatus_.SetErrorCode(code); | 235 lastStatus_.SetErrorCode(code); |
236 } | 236 } |
237 | 237 |
238 void Serialize(Json::Value& target) const | 238 bool Serialize(Json::Value& target) const |
239 { | 239 { |
240 target = Json::objectValue; | 240 target = Json::objectValue; |
241 target["ID"] = id_; | 241 |
242 target["State"] = EnumerationToString(state_); | 242 bool ok; |
243 target["JobType"] = jobType_; | |
244 target["Priority"] = priority_; | |
245 target["CreationTime"] = boost::posix_time::to_iso_string(creationTime_); | |
246 target["Runtime"] = static_cast<unsigned int>(runtime_.total_milliseconds()); | |
247 | 243 |
248 if (state_ == JobState_Running) | 244 if (state_ == JobState_Running) |
249 { | 245 { |
250 // WARNING: Cannot directly access the "job_" member, as long | 246 // WARNING: Cannot directly access the "job_" member, as long |
251 // as a "RunningJob" instance is running. We do not use a | 247 // as a "RunningJob" instance is running. We do not use a |
252 // mutex at the "JobHandler" level, as serialization would be | 248 // mutex at the "JobHandler" level, as serialization would be |
253 // blocked while a step in the job is running. Instead, we | 249 // blocked while a step in the job is running. Instead, we |
254 // save a snapshot of the serialized job. | 250 // save a snapshot of the serialized job. |
255 target["Job"] = lastStatus_.GetSerialized(); | 251 |
252 if (lastStatus_.HasSerialized()) | |
253 { | |
254 target["Job"] = lastStatus_.GetSerialized(); | |
255 ok = true; | |
256 } | |
257 else | |
258 { | |
259 ok = false; | |
260 } | |
261 } | |
262 else | |
263 { | |
264 ok = job_->Serialize(target["Job"]); | |
265 } | |
266 | |
267 if (ok) | |
268 { | |
269 target["ID"] = id_; | |
270 target["State"] = EnumerationToString(state_); | |
271 target["JobType"] = jobType_; | |
272 target["Priority"] = priority_; | |
273 target["CreationTime"] = boost::posix_time::to_iso_string(creationTime_); | |
274 target["Runtime"] = static_cast<unsigned int>(runtime_.total_milliseconds()); | |
275 return true; | |
256 } | 276 } |
257 else | 277 else |
258 { | 278 { |
259 job_->Serialize(target["Job"]); | 279 LOG(WARNING) << "Job backup is not supported for job of type: " << jobType_; |
280 return false; | |
260 } | 281 } |
261 } | 282 } |
262 | 283 |
263 JobHandler(IJobUnserializer& unserializer, | 284 JobHandler(IJobUnserializer& unserializer, |
264 const Json::Value& serialized) : | 285 const Json::Value& serialized) : |
566 | 587 |
567 for (JobsIndex::const_iterator it = jobsIndex_.begin(); | 588 for (JobsIndex::const_iterator it = jobsIndex_.begin(); |
568 it != jobsIndex_.end(); ++it) | 589 it != jobsIndex_.end(); ++it) |
569 { | 590 { |
570 Json::Value v; | 591 Json::Value v; |
571 it->second->Serialize(v); | 592 if (it->second->Serialize(v)) |
572 target.append(v); | 593 { |
594 target.append(v); | |
595 } | |
573 } | 596 } |
574 } | 597 } |
575 | 598 |
576 | 599 |
577 void JobsRegistry::Submit(std::string& id, | 600 void JobsRegistry::Submit(std::string& id, |