comparison Core/JobsEngine/JobsRegistry.cpp @ 2655:c196d76cb8fa jobs

serialization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 05 Jun 2018 17:57:49 +0200
parents a3f0f61a14ca
children a6d3e45eeff5
comparison
equal deleted inserted replaced
2654:761031029aa9 2655:c196d76cb8fa
234 lastStatus_.SetErrorCode(code); 234 lastStatus_.SetErrorCode(code);
235 } 235 }
236 236
237 void Serialize(Json::Value& target) const 237 void Serialize(Json::Value& target) const
238 { 238 {
239 target = Json::objectValue;
240 target["ID"] = id_;
239 target["State"] = EnumerationToString(state_); 241 target["State"] = EnumerationToString(state_);
240 target["JobType"] = jobType_; 242 target["JobType"] = jobType_;
241 target["Priority"] = priority_; 243 target["Priority"] = priority_;
242 target["CreationTime"] = boost::posix_time::to_iso_string(creationTime_); 244 target["CreationTime"] = boost::posix_time::to_iso_string(creationTime_);
243 target["Runtime"] = static_cast<unsigned int>(runtime_.total_milliseconds()); 245 target["Runtime"] = static_cast<unsigned int>(runtime_.total_milliseconds());
256 job_->Serialize(target["Job"]); 258 job_->Serialize(target["Job"]);
257 } 259 }
258 } 260 }
259 261
260 JobHandler(IJobUnserializer& unserializer, 262 JobHandler(IJobUnserializer& unserializer,
261 const std::string& id,
262 const Json::Value& serialized) : 263 const Json::Value& serialized) :
263 id_(id),
264 lastStateChangeTime_(boost::posix_time::microsec_clock::universal_time()), 264 lastStateChangeTime_(boost::posix_time::microsec_clock::universal_time()),
265 pauseScheduled_(false), 265 pauseScheduled_(false),
266 cancelScheduled_(false) 266 cancelScheduled_(false)
267 { 267 {
268 state_ = StringToJobState(IJobUnserializer::GetString(serialized, "State")); 268 id_ = StringToJobState(IJobUnserializer::ReadString(serialized, "ID"));
269 priority_ = IJobUnserializer::GetInteger(serialized, "Priority"); 269 state_ = StringToJobState(IJobUnserializer::ReadString(serialized, "State"));
270 priority_ = IJobUnserializer::ReadInteger(serialized, "Priority");
270 creationTime_ = boost::posix_time::from_iso_string 271 creationTime_ = boost::posix_time::from_iso_string
271 (IJobUnserializer::GetString(serialized, "CreationTime")); 272 (IJobUnserializer::ReadString(serialized, "CreationTime"));
272 runtime_ = boost::posix_time::milliseconds(IJobUnserializer::GetInteger(serialized, "Runtime")); 273 runtime_ = boost::posix_time::milliseconds(IJobUnserializer::ReadInteger(serialized, "Runtime"));
273 274
274 retryTime_ = creationTime_; 275 retryTime_ = creationTime_;
275 276
276 if (state_ == JobState_Retry || 277 if (state_ == JobState_Retry ||
277 state_ == JobState_Running) 278 state_ == JobState_Running)
558 void JobsRegistry::Serialize(Json::Value& target) 559 void JobsRegistry::Serialize(Json::Value& target)
559 { 560 {
560 boost::mutex::scoped_lock lock(mutex_); 561 boost::mutex::scoped_lock lock(mutex_);
561 CheckInvariants(); 562 CheckInvariants();
562 563
563 target = Json::objectValue; 564 target = Json::arrayValue;
564 565
565 for (JobsIndex::const_iterator it = jobsIndex_.begin(); 566 for (JobsIndex::const_iterator it = jobsIndex_.begin();
566 it != jobsIndex_.end(); ++it) 567 it != jobsIndex_.end(); ++it)
567 { 568 {
568 Json::Value& v = target[it->first]; 569 Json::Value v;
569 it->second->Serialize(v); 570 it->second->Serialize(v);
571 target.append(v);
570 } 572 }
571 } 573 }
572 574
573 575
574 void JobsRegistry::Submit(std::string& id, 576 void JobsRegistry::Submit(std::string& id,