Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestApi.cpp @ 2976:cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 06 Dec 2018 12:23:46 +0100 |
parents | eea66afed0db |
children | 4e43e67f8ecf |
comparison
equal
deleted
inserted
replaced
2970:eea66afed0db | 2976:cb5d75143da0 |
---|---|
209 return SerializationToolbox::ReadInteger(body, KEY_PRIORITY); | 209 return SerializationToolbox::ReadInteger(body, KEY_PRIORITY); |
210 } | 210 } |
211 } | 211 } |
212 | 212 |
213 | 213 |
214 void OrthancRestApi::SubmitGenericJob(RestApiOutput& output, | |
215 ServerContext& context, | |
216 IJob* job, | |
217 bool synchronous, | |
218 int priority) | |
219 { | |
220 std::auto_ptr<IJob> raii(job); | |
221 | |
222 if (job == NULL) | |
223 { | |
224 throw OrthancException(ErrorCode_NullPointer); | |
225 } | |
226 | |
227 if (synchronous) | |
228 { | |
229 Json::Value successContent; | |
230 if (context.GetJobsEngine().GetRegistry().SubmitAndWait | |
231 (successContent, raii.release(), priority)) | |
232 { | |
233 // Success in synchronous execution | |
234 output.AnswerJson(successContent); | |
235 } | |
236 else | |
237 { | |
238 // Error during synchronous execution | |
239 output.SignalError(HttpStatus_500_InternalServerError); | |
240 } | |
241 } | |
242 else | |
243 { | |
244 // Asynchronous mode: Submit the job, but don't wait for its completion | |
245 std::string id; | |
246 context.GetJobsEngine().GetRegistry().Submit | |
247 (id, raii.release(), priority); | |
248 | |
249 Json::Value v; | |
250 v["ID"] = id; | |
251 v["Path"] = "/jobs/" + id; | |
252 output.AnswerJson(v); | |
253 } | |
254 } | |
255 | |
256 | |
214 void OrthancRestApi::SubmitGenericJob(RestApiPostCall& call, | 257 void OrthancRestApi::SubmitGenericJob(RestApiPostCall& call, |
215 IJob* job, | 258 IJob* job, |
216 bool isDefaultSynchronous, | 259 bool isDefaultSynchronous, |
217 const Json::Value& body) const | 260 const Json::Value& body) const |
218 { | 261 { |
219 std::auto_ptr<IJob> raii(job); | 262 std::auto_ptr<IJob> raii(job); |
220 | |
221 if (job == NULL) | |
222 { | |
223 throw OrthancException(ErrorCode_NullPointer); | |
224 } | |
225 | 263 |
226 if (body.type() != Json::objectValue) | 264 if (body.type() != Json::objectValue) |
227 { | 265 { |
228 throw OrthancException(ErrorCode_BadFileFormat); | 266 throw OrthancException(ErrorCode_BadFileFormat); |
229 } | 267 } |
230 | 268 |
231 if (IsSynchronousJobRequest(isDefaultSynchronous, body)) | 269 bool synchronous = IsSynchronousJobRequest(isDefaultSynchronous, body); |
232 { | 270 int priority = GetJobRequestPriority(body); |
233 Json::Value successContent; | 271 |
234 if (context_.GetJobsEngine().GetRegistry().SubmitAndWait | 272 SubmitGenericJob(call.GetOutput(), context_, raii.release(), synchronous, priority); |
235 (successContent, raii.release(), GetJobRequestPriority(body))) | |
236 { | |
237 // Success in synchronous execution | |
238 call.GetOutput().AnswerJson(successContent); | |
239 } | |
240 else | |
241 { | |
242 // Error during synchronous execution | |
243 call.GetOutput().SignalError(HttpStatus_500_InternalServerError); | |
244 } | |
245 } | |
246 else | |
247 { | |
248 // Asynchronous mode: Submit the job, but don't wait for its completion | |
249 std::string id; | |
250 context_.GetJobsEngine().GetRegistry().Submit | |
251 (id, raii.release(), GetJobRequestPriority(body)); | |
252 | |
253 Json::Value v; | |
254 v["ID"] = id; | |
255 v["Path"] = "/jobs/" + id; | |
256 call.GetOutput().AnswerJson(v); | |
257 } | |
258 } | 273 } |
259 | 274 |
260 | 275 |
261 void OrthancRestApi::SubmitCommandsJob(RestApiPostCall& call, | 276 void OrthancRestApi::SubmitCommandsJob(RestApiPostCall& call, |
262 SetOfCommandsJob* job, | 277 SetOfCommandsJob* job, |
263 bool isDefaultSynchronous, | 278 bool isDefaultSynchronous, |
264 const Json::Value& body) const | 279 const Json::Value& body) const |
265 { | 280 { |
266 std::auto_ptr<SetOfCommandsJob> raii(job); | 281 std::auto_ptr<SetOfCommandsJob> raii(job); |
267 | 282 |
268 if (job == NULL) | |
269 { | |
270 throw OrthancException(ErrorCode_NullPointer); | |
271 } | |
272 | |
273 if (body.type() != Json::objectValue) | 283 if (body.type() != Json::objectValue) |
274 { | 284 { |
275 throw OrthancException(ErrorCode_BadFileFormat); | 285 throw OrthancException(ErrorCode_BadFileFormat); |
276 } | 286 } |
277 | 287 |