Mercurial > hg > orthanc
annotate OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.cpp @ 5340:0854cc13b4d5
better error reporting if anonymizing a study whose files are missings
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 28 Jun 2023 11:11:34 +0200 |
parents | b5c502bcaf99 |
children | 9ffd6d18daf3 |
rev | line source |
---|---|
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
1 /** |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5150
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5150
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
7 * |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
5277 | 9 * modify it under the terms of the GNU General Public License as |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
12 * |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
5277 | 16 * General Public License for more details. |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
17 * |
5277 | 18 * You should have received a copy of the GNU General Public License |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
20 **/ |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
21 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
22 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
23 #include "ThreadedSetOfInstancesJob.h" |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
24 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
25 #include "../../../OrthancFramework/Sources/Logging.h" |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
26 #include "../../../OrthancFramework/Sources/OrthancException.h" |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
27 #include "../../../OrthancFramework/Sources/SerializationToolbox.h" |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
28 #include "../ServerContext.h" |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
29 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
30 #include <boost/lexical_cast.hpp> |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
31 #include <cassert> |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
32 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
33 namespace Orthanc |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
34 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
35 static const char* EXIT_WORKER_MESSAGE = "exit"; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
36 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
37 ThreadedSetOfInstancesJob::ThreadedSetOfInstancesJob(ServerContext& context, |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
38 bool hasPostProcessing, |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
39 bool keepSource, |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
40 size_t workersCount) : |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
41 hasPostProcessing_(hasPostProcessing), |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
42 started_(false), |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
43 stopRequested_(false), |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
44 permissive_(false), |
5145
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
45 currentStep_(ThreadedJobStep_NotStarted), |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
46 workersCount_(workersCount), |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
47 context_(context), |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
48 keepSource_(keepSource), |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
49 errorCode_(ErrorCode_Success) |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
50 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
51 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
52 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
53 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
54 ThreadedSetOfInstancesJob::~ThreadedSetOfInstancesJob() |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
55 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
56 // no need to lock mutex here since we access variables used only by the "master" thread |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
57 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
58 StopWorkers(); |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
59 WaitWorkersComplete(); |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
60 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
61 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
62 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
63 void ThreadedSetOfInstancesJob::InitWorkers(size_t workersCount) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
64 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
65 // no need to lock mutex here since we access variables used only by the "master" thread |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
66 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
67 for (size_t i = 0; i < workersCount; i++) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
68 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
69 instancesWorkers_.push_back(boost::shared_ptr<boost::thread>(new boost::thread(InstanceWorkerThread, this))); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
70 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
71 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
72 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
73 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
74 void ThreadedSetOfInstancesJob::WaitWorkersComplete() |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
75 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
76 // no need to lock mutex here since we access variables used only by the "master" thread |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
77 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
78 // send a dummy "exit" message to all workers such that they stop waiting for messages on the queue |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
79 for (size_t i = 0; i < instancesWorkers_.size(); i++) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
80 { |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
81 instancesToProcessQueue_.Enqueue(new SingleValueObject<std::string>(EXIT_WORKER_MESSAGE)); |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
82 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
83 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
84 for (size_t i = 0; i < instancesWorkers_.size(); i++) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
85 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
86 if (instancesWorkers_[i]->joinable()) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
87 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
88 instancesWorkers_[i]->join(); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
89 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
90 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
91 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
92 instancesWorkers_.clear(); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
93 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
94 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
95 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
96 void ThreadedSetOfInstancesJob::StopWorkers() |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
97 { |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
98 boost::recursive_mutex::scoped_lock lock(mutex_); |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
99 |
5145
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
100 instancesToProcessQueue_.Clear(); |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
101 stopRequested_ = true; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
102 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
103 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
104 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
105 void ThreadedSetOfInstancesJob::Stop(JobStopReason reason) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
106 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
107 // no need to lock mutex here since we access variables used or set only by the "master" thread |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
108 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
109 if (reason == JobStopReason_Canceled || |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
110 reason == JobStopReason_Failure || |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
111 reason == JobStopReason_Retry) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
112 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
113 // deallocate resources |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
114 StopWorkers(); |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
115 WaitWorkersComplete(); |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
116 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
117 else if (reason == JobStopReason_Paused) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
118 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
119 // keep resources allocated. |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
120 // note that, right now, since all instances are queued from the start, this kind of jobs is not paused while in ProcessingInstances state |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
121 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
122 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
123 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
124 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
125 JobStepResult ThreadedSetOfInstancesJob::Step(const std::string& jobId) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
126 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
127 // no need to lock mutex here since we access variables used or set only by the "master" thread |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
128 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
129 if (!started_) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
130 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
131 throw OrthancException(ErrorCode_InternalError); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
132 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
133 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
134 if (GetInstancesCount() == 0) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
135 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
136 // No instances to handle: We're done |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
137 return JobStepResult::Success(); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
138 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
139 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
140 try |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
141 { |
5145
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
142 if (currentStep_ == ThreadedJobStep_NotStarted) |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
143 { |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
144 // create the workers and enqueue all instances |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
145 for (std::set<std::string>::const_iterator it = instancesToProcess_.begin(); it != instancesToProcess_.end(); ++it) |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
146 { |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
147 instancesToProcessQueue_.Enqueue(new SingleValueObject<std::string>(*it)); |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
148 } |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
149 |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
150 InitWorkers(workersCount_); |
5145
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
151 currentStep_ = ThreadedJobStep_ProcessingInstances; |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
152 } |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
153 else if (currentStep_ == ThreadedJobStep_ProcessingInstances) |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
154 { |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
155 // wait until all instances are processed by the workers |
5145
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
156 if (instancesToProcessQueue_.GetSize() != 0) |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
157 { |
5150
6ff13c95f62f
ThreadedSetOfInstancesJob: reduce cpu consumption of job main thread
Alain Mazy <am@osimis.io>
parents:
5146
diff
changeset
|
158 // "slow down" the job main thread, to avoid using 100% of a core simply to check that other threads are done |
6ff13c95f62f
ThreadedSetOfInstancesJob: reduce cpu consumption of job main thread
Alain Mazy <am@osimis.io>
parents:
5146
diff
changeset
|
159 boost::this_thread::sleep(boost::posix_time::milliseconds(5)); |
6ff13c95f62f
ThreadedSetOfInstancesJob: reduce cpu consumption of job main thread
Alain Mazy <am@osimis.io>
parents:
5146
diff
changeset
|
160 |
5145
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
161 return JobStepResult::Continue(); |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
162 } |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
163 else |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
164 { |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
165 WaitWorkersComplete(); |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
166 |
5145
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
167 // check job has really completed !!! it might have been interrupted because of an error |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
168 if ((processedInstances_.size() != instancesToProcess_.size()) |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
169 || (!IsPermissive() && failedInstances_.size() > 0)) |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
170 { |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
171 return JobStepResult::Failure(GetErrorCode(), NULL); |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
172 } |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
173 |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
174 currentStep_ = ThreadedJobStep_PostProcessingInstances; |
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
175 return JobStepResult::Continue(); |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
176 } |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
177 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
178 else if (currentStep_ == ThreadedJobStep_PostProcessingInstances) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
179 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
180 if (HasPostProcessingStep()) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
181 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
182 PostProcessInstances(); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
183 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
184 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
185 currentStep_ = ThreadedJobStep_Cleanup; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
186 return JobStepResult::Continue(); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
187 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
188 else if (currentStep_ == ThreadedJobStep_Cleanup) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
189 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
190 // clean after the post processing step |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
191 if (HasCleanupStep()) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
192 { |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
193 for (std::set<std::string>::const_iterator it = instancesToProcess_.begin(); it != instancesToProcess_.end(); ++it) |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
194 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
195 Json::Value tmp; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
196 context_.DeleteResource(tmp, *it, ResourceType_Instance); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
197 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
198 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
199 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
200 currentStep_ = ThreadedJobStep_Done; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
201 return JobStepResult::Success(); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
202 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
203 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
204 catch (OrthancException& e) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
205 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
206 if (permissive_) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
207 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
208 LOG(WARNING) << "Ignoring an error in a permissive job: " << e.What(); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
209 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
210 else |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
211 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
212 return JobStepResult::Failure(e); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
213 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
214 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
215 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
216 return JobStepResult::Continue(); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
217 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
218 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
219 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
220 bool ThreadedSetOfInstancesJob::HasPostProcessingStep() const |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
221 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
222 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
223 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
224 return hasPostProcessing_; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
225 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
226 |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
227 void ThreadedSetOfInstancesJob::PostProcessInstances() |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
228 { |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
229 if (HasPostProcessingStep()) |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
230 { |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
231 throw OrthancException(ErrorCode_InternalError, "Job with post-processing should override PostProcessInstances"); |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
232 } |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
233 } |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
234 |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
235 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
236 bool ThreadedSetOfInstancesJob::HasCleanupStep() const |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
237 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
238 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
239 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
240 return !keepSource_; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
241 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
242 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
243 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
244 void ThreadedSetOfInstancesJob::InstanceWorkerThread(ThreadedSetOfInstancesJob* that) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
245 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
246 while (true) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
247 { |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
248 std::unique_ptr<SingleValueObject<std::string> > instanceId(dynamic_cast<SingleValueObject<std::string>*>(that->instancesToProcessQueue_.Dequeue(0))); |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
249 if (that->stopRequested_ // no lock(mutex) to access this variable, this is safe since it's just reading a boolean |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
250 || instanceId->GetValue() == EXIT_WORKER_MESSAGE) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
251 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
252 return; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
253 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
254 |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
255 bool processed = false; |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
256 |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
257 try |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
258 { |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
259 processed = that->HandleInstance(instanceId->GetValue()); |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
260 } |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
261 catch (const Orthanc::OrthancException& e) |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
262 { |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
263 if (that->IsPermissive()) |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
264 { |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
265 LOG(WARNING) << "Ignoring an error in a permissive job: " << e.What(); |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
266 } |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
267 else |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
268 { |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
269 LOG(ERROR) << "Error in a non-permissive job: " << e.What(); |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
270 that->SetErrorCode(e.GetErrorCode()); |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
271 that->StopWorkers(); |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
272 return; |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
273 } |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
274 } |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
275 catch (...) |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
276 { |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
277 LOG(ERROR) << "Native exception while executing a job"; |
5135 | 278 that->SetErrorCode(ErrorCode_InternalError); |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
279 that->StopWorkers(); |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
280 return; |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
281 } |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
282 |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
283 { |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
284 boost::recursive_mutex::scoped_lock lock(that->mutex_); |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
285 |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
286 that->processedInstances_.insert(instanceId->GetValue()); |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
287 |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
288 if (!processed) |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
289 { |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
290 that->failedInstances_.insert(instanceId->GetValue()); |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
291 } |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
292 } |
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
293 |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
294 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
295 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
296 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
297 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
298 size_t ThreadedSetOfInstancesJob::GetInstancesCount() const |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
299 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
300 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
301 |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
302 return instancesToProcess_.size(); |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
303 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
304 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
305 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
306 void ThreadedSetOfInstancesJob::GetFailedInstances(std::set<std::string>& target) const |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
307 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
308 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
309 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
310 target = failedInstances_; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
311 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
312 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
313 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
314 void ThreadedSetOfInstancesJob::GetInstances(std::set<std::string>& target) const |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
315 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
316 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
317 |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
318 target = instancesToProcess_; |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
319 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
320 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
321 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
322 bool ThreadedSetOfInstancesJob::IsFailedInstance(const std::string &instance) const |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
323 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
324 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
325 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
326 return failedInstances_.find(instance) != failedInstances_.end(); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
327 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
328 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
329 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
330 void ThreadedSetOfInstancesJob::Start() |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
331 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
332 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
333 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
334 started_ = true; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
335 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
336 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
337 |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
338 // Reset is called when resubmitting a failed job |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
339 void ThreadedSetOfInstancesJob::Reset() |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
340 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
341 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
342 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
343 if (started_) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
344 { |
5281 | 345 // We actually cannot clean the instances that would have been generated during a previous run |
5146 | 346 // because the generated instances may or may not have the same orthanc ids as the source |
347 // it is too dangerous to guess if they should be deleted or not | |
5145
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
348 currentStep_ = ThreadedJobStep_NotStarted; |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
349 stopRequested_ = false; |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
350 processedInstances_.clear(); |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
351 failedInstances_.clear(); |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
352 instancesToProcessQueue_.Clear(); |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
353 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
354 else |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
355 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
356 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
357 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
358 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
359 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
360 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
361 static const char* KEY_FAILED_INSTANCES = "FailedInstances"; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
362 static const char* KEY_PARENT_RESOURCES = "ParentResources"; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
363 static const char* KEY_DESCRIPTION = "Description"; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
364 static const char* KEY_PERMISSIVE = "Permissive"; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
365 static const char* KEY_CURRENT_STEP = "CurrentStep"; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
366 static const char* KEY_TYPE = "Type"; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
367 static const char* KEY_INSTANCES = "Instances"; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
368 static const char* KEY_INSTANCES_COUNT = "InstancesCount"; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
369 static const char* KEY_FAILED_INSTANCES_COUNT = "FailedInstancesCount"; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
370 static const char* KEY_KEEP_SOURCE = "KeepSource"; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
371 static const char* KEY_WORKERS_COUNT = "WorkersCount"; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
372 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
373 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
374 void ThreadedSetOfInstancesJob::GetPublicContent(Json::Value& target) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
375 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
376 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
377 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
378 target[KEY_DESCRIPTION] = GetDescription(); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
379 target[KEY_INSTANCES_COUNT] = static_cast<uint32_t>(GetInstancesCount()); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
380 target[KEY_FAILED_INSTANCES_COUNT] = static_cast<uint32_t>(failedInstances_.size()); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
381 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
382 if (!parentResources_.empty()) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
383 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
384 SerializationToolbox::WriteSetOfStrings(target, parentResources_, KEY_PARENT_RESOURCES); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
385 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
386 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
387 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
388 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
389 bool ThreadedSetOfInstancesJob::Serialize(Json::Value& target) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
390 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
391 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
392 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
393 target = Json::objectValue; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
394 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
395 std::string type; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
396 GetJobType(type); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
397 target[KEY_TYPE] = type; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
398 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
399 target[KEY_PERMISSIVE] = permissive_; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
400 target[KEY_CURRENT_STEP] = static_cast<unsigned int>(currentStep_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
401 target[KEY_DESCRIPTION] = description_; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
402 target[KEY_KEEP_SOURCE] = keepSource_; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
403 target[KEY_WORKERS_COUNT] = static_cast<unsigned int>(workersCount_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
404 |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
405 SerializationToolbox::WriteSetOfStrings(target, instancesToProcess_, KEY_INSTANCES); |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
406 SerializationToolbox::WriteSetOfStrings(target, failedInstances_, KEY_FAILED_INSTANCES); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
407 SerializationToolbox::WriteSetOfStrings(target, parentResources_, KEY_PARENT_RESOURCES); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
408 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
409 return true; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
410 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
411 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
412 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
413 ThreadedSetOfInstancesJob::ThreadedSetOfInstancesJob(ServerContext& context, |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
414 const Json::Value& source, |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
415 bool hasPostProcessing, |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
416 bool defaultKeepSource) : |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
417 hasPostProcessing_(hasPostProcessing), |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
418 started_(false), |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
419 stopRequested_(false), |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
420 permissive_(false), |
5145
df040c83796c
correctly report ThreadedSetOfInstancesJob progress
Alain Mazy <am@osimis.io>
parents:
5137
diff
changeset
|
421 currentStep_(ThreadedJobStep_NotStarted), |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
422 workersCount_(1), |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
423 context_(context), |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
424 keepSource_(defaultKeepSource), |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
425 errorCode_(ErrorCode_Success) |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
426 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
427 SerializationToolbox::ReadSetOfStrings(failedInstances_, source, KEY_FAILED_INSTANCES); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
428 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
429 if (source.isMember(KEY_PARENT_RESOURCES)) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
430 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
431 // Backward compatibility with Orthanc <= 1.5.6 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
432 SerializationToolbox::ReadSetOfStrings(parentResources_, source, KEY_PARENT_RESOURCES); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
433 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
434 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
435 if (source.isMember(KEY_KEEP_SOURCE)) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
436 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
437 keepSource_ = SerializationToolbox::ReadBoolean(source, KEY_KEEP_SOURCE); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
438 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
439 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
440 if (source.isMember(KEY_WORKERS_COUNT)) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
441 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
442 workersCount_ = SerializationToolbox::ReadUnsignedInteger(source, KEY_WORKERS_COUNT); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
443 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
444 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
445 if (source.isMember(KEY_INSTANCES)) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
446 { |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
447 SerializationToolbox::ReadSetOfStrings(instancesToProcess_, source, KEY_INSTANCES); |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
448 } |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
449 |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
450 if (source.isMember(KEY_CURRENT_STEP)) |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
451 { |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
452 currentStep_ = static_cast<ThreadedJobStep>(SerializationToolbox::ReadUnsignedInteger(source, KEY_CURRENT_STEP)); |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
453 } |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
454 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
455 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
456 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
457 void ThreadedSetOfInstancesJob::SetKeepSource(bool keep) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
458 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
459 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
460 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
461 if (IsStarted()) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
462 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
463 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
464 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
465 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
466 keepSource_ = keep; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
467 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
468 |
5137
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
469 bool ThreadedSetOfInstancesJob::IsKeepSource() const |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
470 { |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
471 boost::recursive_mutex::scoped_lock lock(mutex_); |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
472 |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
473 return keepSource_; |
15109c3f0f7d
added sanity checks in DicomModificationJob + automatically reconstruct resources at the end of a DicomModificationJob
Alain Mazy <am@osimis.io>
parents:
5136
diff
changeset
|
474 } |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
475 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
476 float ThreadedSetOfInstancesJob::GetProgress() |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
477 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
478 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
479 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
480 if (GetInstancesCount() == 0) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
481 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
482 return 1; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
483 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
484 else |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
485 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
486 size_t totalProgress = GetInstancesCount(); |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
487 size_t currentProgress = processedInstances_.size(); |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
488 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
489 if (HasPostProcessingStep()) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
490 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
491 ++totalProgress; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
492 if (currentStep_ > ThreadedJobStep_PostProcessingInstances) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
493 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
494 ++currentProgress; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
495 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
496 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
497 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
498 if (HasCleanupStep()) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
499 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
500 ++totalProgress; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
501 if (currentStep_ > ThreadedJobStep_Cleanup) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
502 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
503 ++currentProgress; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
504 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
505 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
506 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
507 return (static_cast<float>(currentProgress) / |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
508 static_cast<float>(totalProgress)); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
509 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
510 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
511 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
512 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
513 ThreadedSetOfInstancesJob::ThreadedJobStep ThreadedSetOfInstancesJob::GetCurrentStep() const |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
514 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
515 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
516 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
517 return currentStep_; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
518 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
519 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
520 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
521 void ThreadedSetOfInstancesJob::SetDescription(const std::string &description) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
522 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
523 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
524 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
525 description_ = description; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
526 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
527 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
528 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
529 const std::string& ThreadedSetOfInstancesJob::GetDescription() const |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
530 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
531 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
532 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
533 return description_; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
534 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
535 |
5134
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
536 void ThreadedSetOfInstancesJob::SetErrorCode(ErrorCode errorCode) |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
537 { |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
538 boost::recursive_mutex::scoped_lock lock(mutex_); |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
539 |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
540 errorCode_ = errorCode; |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
541 } |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
542 |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
543 ErrorCode ThreadedSetOfInstancesJob::GetErrorCode() const |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
544 { |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
545 boost::recursive_mutex::scoped_lock lock(mutex_); |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
546 |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
547 return errorCode_; |
6aa41d86b948
fix ModificationJob state machine
Alain Mazy <am@osimis.io>
parents:
5130
diff
changeset
|
548 } |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
549 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
550 bool ThreadedSetOfInstancesJob::IsPermissive() const |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
551 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
552 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
553 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
554 return permissive_; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
555 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
556 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
557 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
558 void ThreadedSetOfInstancesJob::SetPermissive(bool permissive) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
559 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
560 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
561 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
562 if (started_) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
563 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
564 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
565 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
566 else |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
567 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
568 permissive_ = permissive; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
569 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
570 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
571 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
572 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
573 bool ThreadedSetOfInstancesJob::IsStarted() const |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
574 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
575 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
576 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
577 return started_; |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
578 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
579 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
580 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
581 void ThreadedSetOfInstancesJob::AddInstances(const std::list<std::string>& instances) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
582 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
583 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
584 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
585 for (std::list<std::string>::const_iterator |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
586 it = instances.begin(); it != instances.end(); ++it) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
587 { |
5136
e71b22a43c0b
Threaded modifications continued: call ReconstructInstance at the end of the modification to update the DB model
Alain Mazy <am@osimis.io>
parents:
5135
diff
changeset
|
588 instancesToProcess_.insert(*it); |
5130
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
589 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
590 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
591 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
592 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
593 void ThreadedSetOfInstancesJob::AddParentResource(const std::string &resource) |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
594 { |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
595 boost::recursive_mutex::scoped_lock lock(mutex_); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
596 |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
597 parentResources_.insert(resource); |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
598 } |
f2dcdbe05884
ResourceModification jobs can now use multiple threads
Alain Mazy <am@osimis.io>
parents:
diff
changeset
|
599 |
5277 | 600 } |