comparison OrthancServer/Sources/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 5130:f2dcdbe05884

ResourceModification jobs can now use multiple threads
author Alain Mazy <am@osimis.io>
date Thu, 05 Jan 2023 17:24:43 +0100
parents 8638522eeda1
children 15109c3f0f7d
comparison
equal deleted inserted replaced
5128:ede035d48b8e 5130:f2dcdbe05884
331 { 331 {
332 job.SetKeepSource(SerializationToolbox::ReadBoolean(body, KEEP_SOURCE)); 332 job.SetKeepSource(SerializationToolbox::ReadBoolean(body, KEEP_SOURCE));
333 } 333 }
334 } 334 }
335 335
336 static void SetKeepSource(ThreadedSetOfInstancesJob& job,
337 const Json::Value& body)
338 {
339 if (body.isMember(KEEP_SOURCE))
340 {
341 job.SetKeepSource(SerializationToolbox::ReadBoolean(body, KEEP_SOURCE));
342 }
343 }
344
336 345
337 static void SubmitModificationJob(std::unique_ptr<DicomModification>& modification, 346 static void SubmitModificationJob(std::unique_ptr<DicomModification>& modification,
338 bool isAnonymization, 347 bool isAnonymization,
339 RestApiPostCall& call, 348 RestApiPostCall& call,
340 const Json::Value& body, 349 const Json::Value& body,
341 ResourceType outputLevel /* unused for multiple resources */, 350 ResourceType outputLevel /* unused for multiple resources */,
342 bool isSingleResource, 351 bool isSingleResource,
343 const std::set<std::string>& resources) 352 const std::set<std::string>& resources)
344 { 353 {
345 ServerContext& context = OrthancRestApi::GetContext(call); 354 ServerContext& context = OrthancRestApi::GetContext(call);
346 355 unsigned int workersCount = 0;
347 std::unique_ptr<ResourceModificationJob> job(new ResourceModificationJob(context)); 356
357 {
358 OrthancConfiguration::ReaderLock lock;
359 workersCount = lock.GetConfiguration().GetJobsEngineWorkersThread("ResourceModification");
360 }
361
362 std::unique_ptr<ResourceModificationJob> job(new ResourceModificationJob(context, workersCount));
348 363
349 if (isSingleResource) // This notably configures the output format 364 if (isSingleResource) // This notably configures the output format
350 { 365 {
351 job->SetSingleResourceModification(modification.release(), outputLevel, isAnonymization); 366 job->SetSingleResourceModification(modification.release(), outputLevel, isAnonymization);
352 } 367 }
364 } 379 }
365 380
366 for (std::set<std::string>::const_iterator 381 for (std::set<std::string>::const_iterator
367 it = resources.begin(); it != resources.end(); ++it) 382 it = resources.begin(); it != resources.end(); ++it)
368 { 383 {
369 context.AddChildInstances(*job, *it); 384 std::list<std::string> instances;
385 context.GetIndex().GetChildInstances(instances, *it);
386 job->AddInstances(instances);
387
388 job->AddParentResource(*it);
370 } 389 }
371 390
372 job->AddTrailingStep(); 391 OrthancRestApi::GetApi(call).SubmitThreadedInstancesJob
373
374 OrthancRestApi::GetApi(call).SubmitCommandsJob
375 (call, job.release(), true /* synchronous by default */, body); 392 (call, job.release(), true /* synchronous by default */, body);
376 } 393 }
377 394
378 395
379 static void SubmitModificationJob(std::unique_ptr<DicomModification>& modification, 396 static void SubmitModificationJob(std::unique_ptr<DicomModification>& modification,