Mercurial > hg > orthanc
comparison Core/JobsEngine/JobsRegistry.cpp @ 2670:c5646f766b3e jobs
serialize jobs as an object
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 09 Jun 2018 14:23:54 +0200 |
parents | eaf10085ffa1 |
children | 8e0bc055d18c |
comparison
equal
deleted
inserted
replaced
2669:eaf10085ffa1 | 2670:c5646f766b3e |
---|---|
39 #include "../Toolbox.h" | 39 #include "../Toolbox.h" |
40 #include "../SerializationToolbox.h" | 40 #include "../SerializationToolbox.h" |
41 | 41 |
42 namespace Orthanc | 42 namespace Orthanc |
43 { | 43 { |
44 static const char* ID = "ID"; | |
45 static const char* STATE = "State"; | 44 static const char* STATE = "State"; |
46 static const char* TYPE = "Type"; | 45 static const char* TYPE = "Type"; |
47 static const char* PRIORITY = "Priority"; | 46 static const char* PRIORITY = "Priority"; |
48 static const char* JOB = "Job"; | 47 static const char* JOB = "Job"; |
49 static const char* JOBS = "Jobs"; | 48 static const char* JOBS = "Jobs"; |
282 ok = job_->Serialize(target[JOB]); | 281 ok = job_->Serialize(target[JOB]); |
283 } | 282 } |
284 | 283 |
285 if (ok) | 284 if (ok) |
286 { | 285 { |
287 target[ID] = id_; | |
288 target[STATE] = EnumerationToString(state_); | 286 target[STATE] = EnumerationToString(state_); |
289 target[PRIORITY] = priority_; | 287 target[PRIORITY] = priority_; |
290 target[CREATION_TIME] = boost::posix_time::to_iso_string(creationTime_); | 288 target[CREATION_TIME] = boost::posix_time::to_iso_string(creationTime_); |
291 target[LAST_CHANGE_TIME] = boost::posix_time::to_iso_string(lastStateChangeTime_); | 289 target[LAST_CHANGE_TIME] = boost::posix_time::to_iso_string(lastStateChangeTime_); |
292 target[RUNTIME] = static_cast<unsigned int>(runtime_.total_milliseconds()); | 290 target[RUNTIME] = static_cast<unsigned int>(runtime_.total_milliseconds()); |
298 return false; | 296 return false; |
299 } | 297 } |
300 } | 298 } |
301 | 299 |
302 JobHandler(IJobUnserializer& unserializer, | 300 JobHandler(IJobUnserializer& unserializer, |
303 const Json::Value& serialized) : | 301 const Json::Value& serialized, |
302 const std::string& id) : | |
303 id_(id), | |
304 pauseScheduled_(false), | 304 pauseScheduled_(false), |
305 cancelScheduled_(false) | 305 cancelScheduled_(false) |
306 { | 306 { |
307 id_ = SerializationToolbox::ReadString(serialized, ID); | |
308 state_ = StringToJobState(SerializationToolbox::ReadString(serialized, STATE)); | 307 state_ = StringToJobState(SerializationToolbox::ReadString(serialized, STATE)); |
309 priority_ = SerializationToolbox::ReadInteger(serialized, PRIORITY); | 308 priority_ = SerializationToolbox::ReadInteger(serialized, PRIORITY); |
310 creationTime_ = boost::posix_time::from_iso_string | 309 creationTime_ = boost::posix_time::from_iso_string |
311 (SerializationToolbox::ReadString(serialized, CREATION_TIME)); | 310 (SerializationToolbox::ReadString(serialized, CREATION_TIME)); |
312 lastStateChangeTime_ = boost::posix_time::from_iso_string | 311 lastStateChangeTime_ = boost::posix_time::from_iso_string |
1229 CheckInvariants(); | 1228 CheckInvariants(); |
1230 | 1229 |
1231 target = Json::objectValue; | 1230 target = Json::objectValue; |
1232 target[TYPE] = JOBS_REGISTRY; | 1231 target[TYPE] = JOBS_REGISTRY; |
1233 target[MAX_COMPLETED_JOBS] = static_cast<unsigned int>(maxCompletedJobs_); | 1232 target[MAX_COMPLETED_JOBS] = static_cast<unsigned int>(maxCompletedJobs_); |
1234 target[JOBS] = Json::arrayValue; | 1233 target[JOBS] = Json::objectValue; |
1235 | 1234 |
1236 for (JobsIndex::const_iterator it = jobsIndex_.begin(); | 1235 for (JobsIndex::const_iterator it = jobsIndex_.begin(); |
1237 it != jobsIndex_.end(); ++it) | 1236 it != jobsIndex_.end(); ++it) |
1238 { | 1237 { |
1239 Json::Value v; | 1238 Json::Value v; |
1240 if (it->second->Serialize(v)) | 1239 if (it->second->Serialize(v)) |
1241 { | 1240 { |
1242 target[JOBS].append(v); | 1241 target[JOBS][it->first] = v; |
1243 } | 1242 } |
1244 } | 1243 } |
1245 } | 1244 } |
1246 | 1245 |
1247 | 1246 |
1248 JobsRegistry::JobsRegistry(IJobUnserializer& unserializer, | 1247 JobsRegistry::JobsRegistry(IJobUnserializer& unserializer, |
1249 const Json::Value& s) | 1248 const Json::Value& s) |
1250 { | 1249 { |
1251 if (SerializationToolbox::ReadString(s, TYPE) != JOBS_REGISTRY || | 1250 if (SerializationToolbox::ReadString(s, TYPE) != JOBS_REGISTRY || |
1252 !s.isMember(JOBS) || | 1251 !s.isMember(JOBS) || |
1253 s[JOBS].type() != Json::arrayValue) | 1252 s[JOBS].type() != Json::objectValue) |
1254 { | 1253 { |
1255 throw OrthancException(ErrorCode_BadFileFormat); | 1254 throw OrthancException(ErrorCode_BadFileFormat); |
1256 } | 1255 } |
1257 | 1256 |
1258 maxCompletedJobs_ = SerializationToolbox::ReadUnsignedInteger(s, MAX_COMPLETED_JOBS); | 1257 maxCompletedJobs_ = SerializationToolbox::ReadUnsignedInteger(s, MAX_COMPLETED_JOBS); |
1259 | 1258 |
1260 for (Json::Value::ArrayIndex i = 0; i < s[JOBS].size(); i++) | 1259 Json::Value::Members members = s[JOBS].getMemberNames(); |
1261 { | 1260 |
1262 std::auto_ptr<JobHandler> job(new JobHandler(unserializer, s[JOBS][i])); | 1261 for (Json::Value::Members::const_iterator it = members.begin(); |
1262 it != members.end(); ++it) | |
1263 { | |
1264 std::auto_ptr<JobHandler> job(new JobHandler(unserializer, s[JOBS][*it], *it)); | |
1263 | 1265 |
1264 std::string id; | 1266 std::string id; |
1265 SubmitInternal(id, job.release(), true); | 1267 SubmitInternal(id, job.release(), true); |
1266 } | 1268 } |
1267 } | 1269 } |