Mercurial > hg > orthanc
annotate Core/JobsEngine/JobsRegistry.cpp @ 3626:02a4eaa76a25
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 25 Jan 2020 10:52:02 +0100 |
parents | fe73717105b6 |
children | 94f4a18a79cc |
rev | line source |
---|---|
2569 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
3060
4e43e67f8ecf
preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2976
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
2569 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../PrecompiledHeaders.h" | |
35 #include "JobsRegistry.h" | |
36 | |
37 #include "../Logging.h" | |
38 #include "../OrthancException.h" | |
39 #include "../Toolbox.h" | |
2656
a6d3e45eeff5
SerializationToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2655
diff
changeset
|
40 #include "../SerializationToolbox.h" |
2569 | 41 |
42 namespace Orthanc | |
43 { | |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
44 static const char* STATE = "State"; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
45 static const char* TYPE = "Type"; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
46 static const char* PRIORITY = "Priority"; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
47 static const char* JOB = "Job"; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
48 static const char* JOBS = "Jobs"; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
49 static const char* JOBS_REGISTRY = "JobsRegistry"; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
50 static const char* CREATION_TIME = "CreationTime"; |
2669
eaf10085ffa1
no passwords in public content of jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2668
diff
changeset
|
51 static const char* LAST_CHANGE_TIME = "LastChangeTime"; |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
52 static const char* RUNTIME = "Runtime"; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
53 |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
54 |
2569 | 55 class JobsRegistry::JobHandler : public boost::noncopyable |
56 { | |
57 private: | |
58 std::string id_; | |
59 JobState state_; | |
2648
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
60 std::string jobType_; |
2569 | 61 std::auto_ptr<IJob> job_; |
62 int priority_; // "+inf()" means highest priority | |
63 boost::posix_time::ptime creationTime_; | |
64 boost::posix_time::ptime lastStateChangeTime_; | |
65 boost::posix_time::time_duration runtime_; | |
66 boost::posix_time::ptime retryTime_; | |
67 bool pauseScheduled_; | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
68 bool cancelScheduled_; |
2569 | 69 JobStatus lastStatus_; |
70 | |
71 void Touch() | |
72 { | |
73 const boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time(); | |
74 | |
75 if (state_ == JobState_Running) | |
76 { | |
77 runtime_ += (now - lastStateChangeTime_); | |
78 } | |
79 | |
80 lastStateChangeTime_ = now; | |
81 } | |
82 | |
83 void SetStateInternal(JobState state) | |
84 { | |
85 state_ = state; | |
86 pauseScheduled_ = false; | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
87 cancelScheduled_ = false; |
2569 | 88 Touch(); |
89 } | |
90 | |
91 public: | |
92 JobHandler(IJob* job, | |
93 int priority) : | |
94 id_(Toolbox::GenerateUuid()), | |
95 state_(JobState_Pending), | |
96 job_(job), | |
97 priority_(priority), | |
98 creationTime_(boost::posix_time::microsec_clock::universal_time()), | |
99 lastStateChangeTime_(creationTime_), | |
100 runtime_(boost::posix_time::milliseconds(0)), | |
101 retryTime_(creationTime_), | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
102 pauseScheduled_(false), |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
103 cancelScheduled_(false) |
2569 | 104 { |
105 if (job == NULL) | |
106 { | |
107 throw OrthancException(ErrorCode_NullPointer); | |
108 } | |
109 | |
2648
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
110 job->GetJobType(jobType_); |
2668
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2667
diff
changeset
|
111 job->Start(); |
2630
00327e989458
creating archives/medias is now a job
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2620
diff
changeset
|
112 |
3240
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
113 lastStatus_ = JobStatus(ErrorCode_Success, "", *job_); |
2569 | 114 } |
115 | |
116 const std::string& GetId() const | |
117 { | |
118 return id_; | |
119 } | |
120 | |
121 IJob& GetJob() const | |
122 { | |
123 assert(job_.get() != NULL); | |
124 return *job_; | |
125 } | |
126 | |
127 void SetPriority(int priority) | |
128 { | |
129 priority_ = priority; | |
130 } | |
131 | |
132 int GetPriority() const | |
133 { | |
134 return priority_; | |
135 } | |
136 | |
137 JobState GetState() const | |
138 { | |
139 return state_; | |
140 } | |
141 | |
142 void SetState(JobState state) | |
143 { | |
144 if (state == JobState_Retry) | |
145 { | |
146 // Use "SetRetryState()" | |
147 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
148 } | |
149 else | |
150 { | |
151 SetStateInternal(state); | |
152 } | |
153 } | |
154 | |
155 void SetRetryState(unsigned int timeout) | |
156 { | |
157 if (state_ == JobState_Running) | |
158 { | |
159 SetStateInternal(JobState_Retry); | |
160 retryTime_ = (boost::posix_time::microsec_clock::universal_time() + | |
161 boost::posix_time::milliseconds(timeout)); | |
162 } | |
163 else | |
164 { | |
165 // Only valid for running jobs | |
166 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
167 } | |
168 } | |
169 | |
170 void SchedulePause() | |
171 { | |
172 if (state_ == JobState_Running) | |
173 { | |
174 pauseScheduled_ = true; | |
175 } | |
176 else | |
177 { | |
178 // Only valid for running jobs | |
179 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
180 } | |
181 } | |
182 | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
183 void ScheduleCancel() |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
184 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
185 if (state_ == JobState_Running) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
186 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
187 cancelScheduled_ = true; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
188 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
189 else |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
190 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
191 // Only valid for running jobs |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
192 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
193 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
194 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
195 |
2569 | 196 bool IsPauseScheduled() |
197 { | |
198 return pauseScheduled_; | |
199 } | |
200 | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
201 bool IsCancelScheduled() |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
202 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
203 return cancelScheduled_; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
204 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
205 |
2569 | 206 bool IsRetryReady(const boost::posix_time::ptime& now) const |
207 { | |
208 if (state_ != JobState_Retry) | |
209 { | |
210 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
211 } | |
212 else | |
213 { | |
214 return retryTime_ <= now; | |
215 } | |
216 } | |
217 | |
218 const boost::posix_time::ptime& GetCreationTime() const | |
219 { | |
220 return creationTime_; | |
221 } | |
222 | |
223 const boost::posix_time::ptime& GetLastStateChangeTime() const | |
224 { | |
225 return lastStateChangeTime_; | |
226 } | |
227 | |
2669
eaf10085ffa1
no passwords in public content of jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2668
diff
changeset
|
228 void SetLastStateChangeTime(const boost::posix_time::ptime& time) |
eaf10085ffa1
no passwords in public content of jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2668
diff
changeset
|
229 { |
eaf10085ffa1
no passwords in public content of jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2668
diff
changeset
|
230 lastStateChangeTime_ = time; |
eaf10085ffa1
no passwords in public content of jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2668
diff
changeset
|
231 } |
eaf10085ffa1
no passwords in public content of jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2668
diff
changeset
|
232 |
2569 | 233 const boost::posix_time::time_duration& GetRuntime() const |
234 { | |
235 return runtime_; | |
236 } | |
237 | |
238 const JobStatus& GetLastStatus() const | |
239 { | |
240 return lastStatus_; | |
241 } | |
242 | |
243 void SetLastStatus(const JobStatus& status) | |
244 { | |
245 lastStatus_ = status; | |
246 Touch(); | |
247 } | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
248 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
249 void SetLastErrorCode(ErrorCode code) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
250 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
251 lastStatus_.SetErrorCode(code); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
252 } |
2648
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
253 |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
254 bool Serialize(Json::Value& target) const |
2648
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
255 { |
2655 | 256 target = Json::objectValue; |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
257 |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
258 bool ok; |
2648
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
259 |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
260 if (state_ == JobState_Running) |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
261 { |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
262 // WARNING: Cannot directly access the "job_" member, as long |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
263 // as a "RunningJob" instance is running. We do not use a |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
264 // mutex at the "JobHandler" level, as serialization would be |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
265 // blocked while a step in the job is running. Instead, we |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
266 // save a snapshot of the serialized job. (*) |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
267 |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
268 if (lastStatus_.HasSerialized()) |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
269 { |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
270 target[JOB] = lastStatus_.GetSerialized(); |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
271 ok = true; |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
272 } |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
273 else |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
274 { |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
275 ok = false; |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
276 } |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
277 } |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
278 else |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
279 { |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
280 ok = job_->Serialize(target[JOB]); |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
281 } |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
282 |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
283 if (ok) |
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
284 { |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
285 target[STATE] = EnumerationToString(state_); |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
286 target[PRIORITY] = priority_; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
287 target[CREATION_TIME] = boost::posix_time::to_iso_string(creationTime_); |
2669
eaf10085ffa1
no passwords in public content of jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2668
diff
changeset
|
288 target[LAST_CHANGE_TIME] = boost::posix_time::to_iso_string(lastStateChangeTime_); |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
289 target[RUNTIME] = static_cast<unsigned int>(runtime_.total_milliseconds()); |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
290 return true; |
2648
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
291 } |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
292 else |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
293 { |
2939 | 294 VLOG(1) << "Job backup is not supported for job of type: " << jobType_; |
2663
228e2783ce83
some jobs might not be serializable
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2656
diff
changeset
|
295 return false; |
2648
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
296 } |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
297 } |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
298 |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
299 JobHandler(IJobUnserializer& unserializer, |
2670
c5646f766b3e
serialize jobs as an object
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2669
diff
changeset
|
300 const Json::Value& serialized, |
c5646f766b3e
serialize jobs as an object
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2669
diff
changeset
|
301 const std::string& id) : |
c5646f766b3e
serialize jobs as an object
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2669
diff
changeset
|
302 id_(id), |
2648
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
303 pauseScheduled_(false), |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
304 cancelScheduled_(false) |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
305 { |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
306 state_ = StringToJobState(SerializationToolbox::ReadString(serialized, STATE)); |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
307 priority_ = SerializationToolbox::ReadInteger(serialized, PRIORITY); |
2648
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
308 creationTime_ = boost::posix_time::from_iso_string |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
309 (SerializationToolbox::ReadString(serialized, CREATION_TIME)); |
2669
eaf10085ffa1
no passwords in public content of jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2668
diff
changeset
|
310 lastStateChangeTime_ = boost::posix_time::from_iso_string |
eaf10085ffa1
no passwords in public content of jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2668
diff
changeset
|
311 (SerializationToolbox::ReadString(serialized, LAST_CHANGE_TIME)); |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
312 runtime_ = boost::posix_time::milliseconds |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
313 (SerializationToolbox::ReadInteger(serialized, RUNTIME)); |
2648
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
314 |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
315 retryTime_ = creationTime_; |
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
316 |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
317 job_.reset(unserializer.UnserializeJob(serialized[JOB])); |
2652 | 318 job_->GetJobType(jobType_); |
319 job_->Start(); | |
2648
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
320 |
3240
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
321 lastStatus_ = JobStatus(ErrorCode_Success, "", *job_); |
2648
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
322 } |
2569 | 323 }; |
324 | |
325 | |
326 bool JobsRegistry::PriorityComparator::operator() (JobHandler*& a, | |
327 JobHandler*& b) const | |
328 { | |
329 return a->GetPriority() < b->GetPriority(); | |
330 } | |
331 | |
332 | |
333 #if defined(NDEBUG) | |
334 void JobsRegistry::CheckInvariants() const | |
335 { | |
336 } | |
337 | |
338 #else | |
339 bool JobsRegistry::IsPendingJob(const JobHandler& job) const | |
340 { | |
341 PendingJobs copy = pendingJobs_; | |
342 while (!copy.empty()) | |
343 { | |
344 if (copy.top() == &job) | |
345 { | |
346 return true; | |
347 } | |
348 | |
349 copy.pop(); | |
350 } | |
351 | |
352 return false; | |
353 } | |
354 | |
355 bool JobsRegistry::IsCompletedJob(JobHandler& job) const | |
356 { | |
357 for (CompletedJobs::const_iterator it = completedJobs_.begin(); | |
358 it != completedJobs_.end(); ++it) | |
359 { | |
360 if (*it == &job) | |
361 { | |
362 return true; | |
363 } | |
364 } | |
365 | |
366 return false; | |
367 } | |
368 | |
369 bool JobsRegistry::IsRetryJob(JobHandler& job) const | |
370 { | |
371 return retryJobs_.find(&job) != retryJobs_.end(); | |
372 } | |
373 | |
374 void JobsRegistry::CheckInvariants() const | |
375 { | |
376 { | |
377 PendingJobs copy = pendingJobs_; | |
378 while (!copy.empty()) | |
379 { | |
380 assert(copy.top()->GetState() == JobState_Pending); | |
381 copy.pop(); | |
382 } | |
383 } | |
384 | |
385 assert(completedJobs_.size() <= maxCompletedJobs_); | |
386 | |
387 for (CompletedJobs::const_iterator it = completedJobs_.begin(); | |
388 it != completedJobs_.end(); ++it) | |
389 { | |
390 assert((*it)->GetState() == JobState_Success || | |
391 (*it)->GetState() == JobState_Failure); | |
392 } | |
393 | |
394 for (RetryJobs::const_iterator it = retryJobs_.begin(); | |
395 it != retryJobs_.end(); ++it) | |
396 { | |
397 assert((*it)->GetState() == JobState_Retry); | |
398 } | |
399 | |
400 for (JobsIndex::const_iterator it = jobsIndex_.begin(); | |
401 it != jobsIndex_.end(); ++it) | |
402 { | |
403 JobHandler& job = *it->second; | |
404 | |
405 assert(job.GetId() == it->first); | |
406 | |
407 switch (job.GetState()) | |
408 { | |
409 case JobState_Pending: | |
410 assert(!IsRetryJob(job) && IsPendingJob(job) && !IsCompletedJob(job)); | |
411 break; | |
412 | |
413 case JobState_Success: | |
414 case JobState_Failure: | |
415 assert(!IsRetryJob(job) && !IsPendingJob(job) && IsCompletedJob(job)); | |
416 break; | |
417 | |
418 case JobState_Retry: | |
419 assert(IsRetryJob(job) && !IsPendingJob(job) && !IsCompletedJob(job)); | |
420 break; | |
421 | |
422 case JobState_Running: | |
423 case JobState_Paused: | |
424 assert(!IsRetryJob(job) && !IsPendingJob(job) && !IsCompletedJob(job)); | |
425 break; | |
426 | |
427 default: | |
428 throw OrthancException(ErrorCode_InternalError); | |
429 } | |
430 } | |
431 } | |
432 #endif | |
433 | |
434 | |
435 void JobsRegistry::ForgetOldCompletedJobs() | |
436 { | |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
437 while (completedJobs_.size() > maxCompletedJobs_) |
2569 | 438 { |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
439 assert(completedJobs_.front() != NULL); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
440 |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
441 std::string id = completedJobs_.front()->GetId(); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
442 assert(jobsIndex_.find(id) != jobsIndex_.end()); |
2569 | 443 |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
444 jobsIndex_.erase(id); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
445 delete(completedJobs_.front()); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
446 completedJobs_.pop_front(); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
447 } |
2569 | 448 |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
449 CheckInvariants(); |
2569 | 450 } |
451 | |
452 | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
453 void JobsRegistry::SetCompletedJob(JobHandler& job, |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
454 bool success) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
455 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
456 job.SetState(success ? JobState_Success : JobState_Failure); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
457 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
458 completedJobs_.push_back(&job); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
459 someJobComplete_.notify_all(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
460 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
461 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
462 |
2569 | 463 void JobsRegistry::MarkRunningAsCompleted(JobHandler& job, |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
464 CompletedReason reason) |
2569 | 465 { |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
466 const char* tmp; |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
467 |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
468 switch (reason) |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
469 { |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
470 case CompletedReason_Success: |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
471 tmp = "success"; |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
472 break; |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
473 |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
474 case CompletedReason_Failure: |
3371 | 475 tmp = "failure"; |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
476 break; |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
477 |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
478 case CompletedReason_Canceled: |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
479 tmp = "cancel"; |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
480 break; |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
481 |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
482 default: |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
483 throw OrthancException(ErrorCode_InternalError); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
484 } |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
485 |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
486 LOG(INFO) << "Job has completed with " << tmp << ": " << job.GetId(); |
2569 | 487 |
488 CheckInvariants(); | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
489 |
2569 | 490 assert(job.GetState() == JobState_Running); |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
491 SetCompletedJob(job, reason == CompletedReason_Success); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
492 |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
493 if (reason == CompletedReason_Canceled) |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
494 { |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
495 job.SetLastErrorCode(ErrorCode_CanceledJob); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
496 } |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
497 |
2673
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
498 if (observer_ != NULL) |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
499 { |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
500 if (reason == CompletedReason_Success) |
2673
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
501 { |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
502 observer_->SignalJobSuccess(job.GetId()); |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
503 } |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
504 else |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
505 { |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
506 observer_->SignalJobFailure(job.GetId()); |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
507 } |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
508 } |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
509 |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
510 // WARNING: The following call might make "job" invalid if the job |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
511 // history size is empty |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
512 ForgetOldCompletedJobs(); |
2569 | 513 } |
514 | |
515 | |
516 void JobsRegistry::MarkRunningAsRetry(JobHandler& job, | |
517 unsigned int timeout) | |
518 { | |
519 LOG(INFO) << "Job scheduled for retry in " << timeout << "ms: " << job.GetId(); | |
520 | |
521 CheckInvariants(); | |
522 | |
523 assert(job.GetState() == JobState_Running && | |
524 retryJobs_.find(&job) == retryJobs_.end()); | |
525 | |
526 retryJobs_.insert(&job); | |
527 job.SetRetryState(timeout); | |
528 | |
529 CheckInvariants(); | |
530 } | |
531 | |
532 | |
533 void JobsRegistry::MarkRunningAsPaused(JobHandler& job) | |
534 { | |
535 LOG(INFO) << "Job paused: " << job.GetId(); | |
536 | |
537 CheckInvariants(); | |
538 assert(job.GetState() == JobState_Running); | |
539 | |
540 job.SetState(JobState_Paused); | |
541 | |
542 CheckInvariants(); | |
543 } | |
544 | |
545 | |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
546 bool JobsRegistry::GetStateInternal(JobState& state, |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
547 const std::string& id) |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
548 { |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
549 CheckInvariants(); |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
550 |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
551 JobsIndex::const_iterator it = jobsIndex_.find(id); |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
552 if (it == jobsIndex_.end()) |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
553 { |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
554 return false; |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
555 } |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
556 else |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
557 { |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
558 state = it->second->GetState(); |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
559 return true; |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
560 } |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
561 } |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
562 |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
563 |
2569 | 564 JobsRegistry::~JobsRegistry() |
565 { | |
566 for (JobsIndex::iterator it = jobsIndex_.begin(); it != jobsIndex_.end(); ++it) | |
567 { | |
568 assert(it->second != NULL); | |
569 delete it->second; | |
570 } | |
571 } | |
572 | |
573 | |
2620
1232922c8793
speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2600
diff
changeset
|
574 void JobsRegistry::SetMaxCompletedJobs(size_t n) |
2569 | 575 { |
576 boost::mutex::scoped_lock lock(mutex_); | |
577 CheckInvariants(); | |
578 | |
2620
1232922c8793
speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2600
diff
changeset
|
579 LOG(INFO) << "The size of the history of the jobs engine is set to: " << n << " job(s)"; |
1232922c8793
speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2600
diff
changeset
|
580 |
1232922c8793
speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2600
diff
changeset
|
581 maxCompletedJobs_ = n; |
2569 | 582 ForgetOldCompletedJobs(); |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
583 } |
2569 | 584 |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
585 |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
586 size_t JobsRegistry::GetMaxCompletedJobs() |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
587 { |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
588 boost::mutex::scoped_lock lock(mutex_); |
2569 | 589 CheckInvariants(); |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
590 return maxCompletedJobs_; |
2569 | 591 } |
592 | |
593 | |
594 void JobsRegistry::ListJobs(std::set<std::string>& target) | |
595 { | |
596 boost::mutex::scoped_lock lock(mutex_); | |
597 CheckInvariants(); | |
598 | |
599 for (JobsIndex::const_iterator it = jobsIndex_.begin(); | |
600 it != jobsIndex_.end(); ++it) | |
601 { | |
602 target.insert(it->first); | |
603 } | |
604 } | |
605 | |
606 | |
607 bool JobsRegistry::GetJobInfo(JobInfo& target, | |
608 const std::string& id) | |
609 { | |
610 boost::mutex::scoped_lock lock(mutex_); | |
611 CheckInvariants(); | |
612 | |
613 JobsIndex::const_iterator found = jobsIndex_.find(id); | |
614 | |
615 if (found == jobsIndex_.end()) | |
616 { | |
617 return false; | |
618 } | |
619 else | |
620 { | |
621 const JobHandler& handler = *found->second; | |
622 target = JobInfo(handler.GetId(), | |
623 handler.GetPriority(), | |
624 handler.GetState(), | |
625 handler.GetLastStatus(), | |
626 handler.GetCreationTime(), | |
627 handler.GetLastStateChangeTime(), | |
628 handler.GetRuntime()); | |
629 return true; | |
630 } | |
631 } | |
632 | |
633 | |
2976
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
634 bool JobsRegistry::GetJobOutput(std::string& output, |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
635 MimeType& mime, |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
636 const std::string& job, |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
637 const std::string& key) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
638 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
639 boost::mutex::scoped_lock lock(mutex_); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
640 CheckInvariants(); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
641 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
642 JobsIndex::const_iterator found = jobsIndex_.find(job); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
643 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
644 if (found == jobsIndex_.end()) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
645 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
646 return false; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
647 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
648 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
649 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
650 const JobHandler& handler = *found->second; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
651 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
652 if (handler.GetState() == JobState_Success) |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
653 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
654 return handler.GetJob().GetOutput(output, mime, key); |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
655 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
656 else |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
657 { |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
658 return false; |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
659 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
660 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
661 } |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
662 |
cb5d75143da0
Asynchronous generation of ZIP archives and DICOM medias
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2954
diff
changeset
|
663 |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
664 void JobsRegistry::SubmitInternal(std::string& id, |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
665 JobHandler* handler) |
2648
e1893d31652a
serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2630
diff
changeset
|
666 { |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
667 if (handler == NULL) |
2668
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2667
diff
changeset
|
668 { |
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2667
diff
changeset
|
669 throw OrthancException(ErrorCode_NullPointer); |
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2667
diff
changeset
|
670 } |
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2667
diff
changeset
|
671 |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
672 std::auto_ptr<JobHandler> protection(handler); |
2669
eaf10085ffa1
no passwords in public content of jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2668
diff
changeset
|
673 |
2673
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
674 { |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
675 boost::mutex::scoped_lock lock(mutex_); |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
676 CheckInvariants(); |
2569 | 677 |
2673
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
678 id = handler->GetId(); |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
679 int priority = handler->GetPriority(); |
2569 | 680 |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
681 jobsIndex_.insert(std::make_pair(id, protection.release())); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
682 |
2673
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
683 switch (handler->GetState()) |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
684 { |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
685 case JobState_Pending: |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
686 case JobState_Retry: |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
687 case JobState_Running: |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
688 handler->SetState(JobState_Pending); |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
689 pendingJobs_.push(handler); |
2673
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
690 pendingJobAvailable_.notify_one(); |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
691 break; |
2668
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2667
diff
changeset
|
692 |
2673
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
693 case JobState_Success: |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
694 SetCompletedJob(*handler, true); |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
695 break; |
2668
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2667
diff
changeset
|
696 |
2673
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
697 case JobState_Failure: |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
698 SetCompletedJob(*handler, false); |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
699 break; |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
700 |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
701 case JobState_Paused: |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
702 break; |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
703 |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
704 default: |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2950
diff
changeset
|
705 { |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2950
diff
changeset
|
706 std::string details = ("A job should not be loaded from state: " + |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2950
diff
changeset
|
707 std::string(EnumerationToString(handler->GetState()))); |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2950
diff
changeset
|
708 throw OrthancException(ErrorCode_InternalError, details); |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2950
diff
changeset
|
709 } |
2673
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
710 } |
2668
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2667
diff
changeset
|
711 |
2673
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
712 LOG(INFO) << "New job submitted with priority " << priority << ": " << id; |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
713 |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
714 if (observer_ != NULL) |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
715 { |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
716 observer_->SignalJobSubmitted(id); |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
717 } |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
718 |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
719 // WARNING: The following call might make "handler" invalid if |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
720 // the job history size is empty |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
721 ForgetOldCompletedJobs(); |
2668
d26dd081df97
saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2667
diff
changeset
|
722 } |
2569 | 723 } |
724 | |
725 | |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
726 void JobsRegistry::Submit(std::string& id, |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
727 IJob* job, // Takes ownership |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
728 int priority) |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
729 { |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
730 SubmitInternal(id, new JobHandler(job, priority)); |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
731 } |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
732 |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
733 |
2569 | 734 void JobsRegistry::Submit(IJob* job, // Takes ownership |
735 int priority) | |
736 { | |
737 std::string id; | |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
738 SubmitInternal(id, new JobHandler(job, priority)); |
2569 | 739 } |
740 | |
741 | |
3240
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
742 void JobsRegistry::SubmitAndWait(Json::Value& successContent, |
2867 | 743 IJob* job, // Takes ownership |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
744 int priority) |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
745 { |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
746 std::string id; |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
747 Submit(id, job, priority); |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
748 |
2867 | 749 JobState state = JobState_Pending; // Dummy initialization |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
750 |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
751 { |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
752 boost::mutex::scoped_lock lock(mutex_); |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
753 |
2867 | 754 for (;;) |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
755 { |
2867 | 756 if (!GetStateInternal(state, id)) |
757 { | |
3162
94a4f75cc746
Fix issue #119 (/patients/.../archive returns a 500 when JobsHistorySize is 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
758 // Job has finished and has been lost (typically happens if |
94a4f75cc746
Fix issue #119 (/patients/.../archive returns a 500 when JobsHistorySize is 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
759 // "JobsHistorySize" is 0) |
94a4f75cc746
Fix issue #119 (/patients/.../archive returns a 500 when JobsHistorySize is 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
760 throw OrthancException(ErrorCode_InexistentItem, |
94a4f75cc746
Fix issue #119 (/patients/.../archive returns a 500 when JobsHistorySize is 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
761 "Cannot retrieve the status of the job, " |
94a4f75cc746
Fix issue #119 (/patients/.../archive returns a 500 when JobsHistorySize is 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
762 "make sure that \"JobsHistorySize\" is not 0"); |
2867 | 763 } |
764 else if (state == JobState_Failure) | |
765 { | |
766 // Failure | |
3240
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
767 JobsIndex::const_iterator it = jobsIndex_.find(id); |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
768 if (it != jobsIndex_.end()) // Should always be true, already tested in GetStateInternal() |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
769 { |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
770 ErrorCode code = it->second->GetLastStatus().GetErrorCode(); |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
771 const std::string& details = it->second->GetLastStatus().GetDetails(); |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
772 |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
773 if (details.empty()) |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
774 { |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
775 throw OrthancException(code); |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
776 } |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
777 else |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
778 { |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
779 throw OrthancException(code, details); |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
780 } |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
781 } |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
782 else |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
783 { |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
784 throw OrthancException(ErrorCode_InternalError); |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
785 } |
2867 | 786 } |
787 else if (state == JobState_Success) | |
788 { | |
789 // Success, try and retrieve the status of the job | |
790 JobsIndex::const_iterator it = jobsIndex_.find(id); | |
791 if (it == jobsIndex_.end()) | |
792 { | |
793 // Should not happen | |
794 state = JobState_Failure; | |
795 } | |
796 else | |
797 { | |
798 const JobStatus& status = it->second->GetLastStatus(); | |
799 successContent = status.GetPublicContent(); | |
800 } | |
801 | |
3240
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
802 return; |
2867 | 803 } |
804 else | |
805 { | |
806 // This job has not finished yet, wait for new completion | |
807 someJobComplete_.wait(lock); | |
808 } | |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
809 } |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
810 } |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
811 } |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
812 |
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
813 |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
814 bool JobsRegistry::SetPriority(const std::string& id, |
2569 | 815 int priority) |
816 { | |
817 LOG(INFO) << "Changing priority to " << priority << " for job: " << id; | |
818 | |
819 boost::mutex::scoped_lock lock(mutex_); | |
820 CheckInvariants(); | |
821 | |
822 JobsIndex::iterator found = jobsIndex_.find(id); | |
823 | |
824 if (found == jobsIndex_.end()) | |
825 { | |
826 LOG(WARNING) << "Unknown job: " << id; | |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
827 return false; |
2569 | 828 } |
829 else | |
830 { | |
831 found->second->SetPriority(priority); | |
832 | |
833 if (found->second->GetState() == JobState_Pending) | |
834 { | |
835 // If the job is pending, we need to reconstruct the | |
836 // priority queue, as the heap condition has changed | |
837 | |
838 PendingJobs copy; | |
839 std::swap(copy, pendingJobs_); | |
840 | |
841 assert(pendingJobs_.empty()); | |
842 while (!copy.empty()) | |
843 { | |
844 pendingJobs_.push(copy.top()); | |
845 copy.pop(); | |
846 } | |
847 } | |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
848 |
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
849 CheckInvariants(); |
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
850 return true; |
2569 | 851 } |
852 } | |
853 | |
854 | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
855 void JobsRegistry::RemovePendingJob(const std::string& id) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
856 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
857 // If the job is pending, we need to reconstruct the priority |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
858 // queue to remove it |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
859 PendingJobs copy; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
860 std::swap(copy, pendingJobs_); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
861 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
862 assert(pendingJobs_.empty()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
863 while (!copy.empty()) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
864 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
865 if (copy.top()->GetId() != id) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
866 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
867 pendingJobs_.push(copy.top()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
868 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
869 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
870 copy.pop(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
871 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
872 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
873 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
874 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
875 void JobsRegistry::RemoveRetryJob(JobHandler* handler) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
876 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
877 RetryJobs::iterator item = retryJobs_.find(handler); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
878 assert(item != retryJobs_.end()); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
879 retryJobs_.erase(item); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
880 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
881 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
882 |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
883 bool JobsRegistry::Pause(const std::string& id) |
2569 | 884 { |
885 LOG(INFO) << "Pausing job: " << id; | |
886 | |
887 boost::mutex::scoped_lock lock(mutex_); | |
888 CheckInvariants(); | |
889 | |
890 JobsIndex::iterator found = jobsIndex_.find(id); | |
891 | |
892 if (found == jobsIndex_.end()) | |
893 { | |
894 LOG(WARNING) << "Unknown job: " << id; | |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
895 return false; |
2569 | 896 } |
897 else | |
898 { | |
899 switch (found->second->GetState()) | |
900 { | |
901 case JobState_Pending: | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
902 RemovePendingJob(id); |
2569 | 903 found->second->SetState(JobState_Paused); |
904 break; | |
905 | |
906 case JobState_Retry: | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
907 RemoveRetryJob(found->second); |
2569 | 908 found->second->SetState(JobState_Paused); |
909 break; | |
910 | |
911 case JobState_Paused: | |
912 case JobState_Success: | |
913 case JobState_Failure: | |
914 // Nothing to be done | |
915 break; | |
916 | |
917 case JobState_Running: | |
918 found->second->SchedulePause(); | |
919 break; | |
920 | |
921 default: | |
922 throw OrthancException(ErrorCode_InternalError); | |
923 } | |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
924 |
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
925 CheckInvariants(); |
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
926 return true; |
2569 | 927 } |
928 } | |
929 | |
930 | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
931 bool JobsRegistry::Cancel(const std::string& id) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
932 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
933 LOG(INFO) << "Canceling job: " << id; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
934 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
935 boost::mutex::scoped_lock lock(mutex_); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
936 CheckInvariants(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
937 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
938 JobsIndex::iterator found = jobsIndex_.find(id); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
939 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
940 if (found == jobsIndex_.end()) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
941 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
942 LOG(WARNING) << "Unknown job: " << id; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
943 return false; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
944 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
945 else |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
946 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
947 switch (found->second->GetState()) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
948 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
949 case JobState_Pending: |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
950 RemovePendingJob(id); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
951 SetCompletedJob(*found->second, false); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
952 found->second->SetLastErrorCode(ErrorCode_CanceledJob); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
953 break; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
954 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
955 case JobState_Retry: |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
956 RemoveRetryJob(found->second); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
957 SetCompletedJob(*found->second, false); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
958 found->second->SetLastErrorCode(ErrorCode_CanceledJob); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
959 break; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
960 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
961 case JobState_Paused: |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
962 SetCompletedJob(*found->second, false); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
963 found->second->SetLastErrorCode(ErrorCode_CanceledJob); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
964 break; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
965 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
966 case JobState_Success: |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
967 case JobState_Failure: |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
968 // Nothing to be done |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
969 break; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
970 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
971 case JobState_Running: |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
972 found->second->ScheduleCancel(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
973 break; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
974 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
975 default: |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
976 throw OrthancException(ErrorCode_InternalError); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
977 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
978 |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
979 // WARNING: The following call might make "handler" invalid if |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
980 // the job history size is empty |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
981 ForgetOldCompletedJobs(); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
982 |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
983 return true; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
984 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
985 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
986 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
987 |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
988 bool JobsRegistry::Resume(const std::string& id) |
2569 | 989 { |
990 LOG(INFO) << "Resuming job: " << id; | |
991 | |
992 boost::mutex::scoped_lock lock(mutex_); | |
993 CheckInvariants(); | |
994 | |
995 JobsIndex::iterator found = jobsIndex_.find(id); | |
996 | |
997 if (found == jobsIndex_.end()) | |
998 { | |
999 LOG(WARNING) << "Unknown job: " << id; | |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
1000 return false; |
2569 | 1001 } |
1002 else if (found->second->GetState() != JobState_Paused) | |
1003 { | |
1004 LOG(WARNING) << "Cannot resume a job that is not paused: " << id; | |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
1005 return false; |
2569 | 1006 } |
1007 else | |
1008 { | |
1009 found->second->SetState(JobState_Pending); | |
1010 pendingJobs_.push(found->second); | |
1011 pendingJobAvailable_.notify_one(); | |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
1012 CheckInvariants(); |
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
1013 return true; |
2569 | 1014 } |
1015 } | |
1016 | |
1017 | |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
1018 bool JobsRegistry::Resubmit(const std::string& id) |
2569 | 1019 { |
1020 LOG(INFO) << "Resubmitting failed job: " << id; | |
1021 | |
1022 boost::mutex::scoped_lock lock(mutex_); | |
1023 CheckInvariants(); | |
1024 | |
1025 JobsIndex::iterator found = jobsIndex_.find(id); | |
1026 | |
1027 if (found == jobsIndex_.end()) | |
1028 { | |
1029 LOG(WARNING) << "Unknown job: " << id; | |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
1030 return false; |
2569 | 1031 } |
1032 else if (found->second->GetState() != JobState_Failure) | |
1033 { | |
1034 LOG(WARNING) << "Cannot resubmit a job that has not failed: " << id; | |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
1035 return false; |
2569 | 1036 } |
1037 else | |
1038 { | |
2812
ea7aea6f6a95
improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2673
diff
changeset
|
1039 found->second->GetJob().Reset(); |
2583
1b6a6d80b6f2
OrthancPeerStoreJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2581
diff
changeset
|
1040 |
2569 | 1041 bool ok = false; |
1042 for (CompletedJobs::iterator it = completedJobs_.begin(); | |
1043 it != completedJobs_.end(); ++it) | |
1044 { | |
1045 if (*it == found->second) | |
1046 { | |
1047 ok = true; | |
1048 completedJobs_.erase(it); | |
1049 break; | |
1050 } | |
1051 } | |
1052 | |
1053 assert(ok); | |
1054 | |
1055 found->second->SetState(JobState_Pending); | |
1056 pendingJobs_.push(found->second); | |
1057 pendingJobAvailable_.notify_one(); | |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
1058 |
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
1059 CheckInvariants(); |
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2570
diff
changeset
|
1060 return true; |
2569 | 1061 } |
1062 } | |
1063 | |
1064 | |
1065 void JobsRegistry::ScheduleRetries() | |
1066 { | |
1067 boost::mutex::scoped_lock lock(mutex_); | |
1068 CheckInvariants(); | |
1069 | |
1070 RetryJobs copy; | |
1071 std::swap(copy, retryJobs_); | |
1072 | |
1073 const boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time(); | |
1074 | |
1075 assert(retryJobs_.empty()); | |
1076 for (RetryJobs::iterator it = copy.begin(); it != copy.end(); ++it) | |
1077 { | |
1078 if ((*it)->IsRetryReady(now)) | |
1079 { | |
1080 LOG(INFO) << "Retrying job: " << (*it)->GetId(); | |
1081 (*it)->SetState(JobState_Pending); | |
1082 pendingJobs_.push(*it); | |
1083 pendingJobAvailable_.notify_one(); | |
1084 } | |
1085 else | |
1086 { | |
1087 retryJobs_.insert(*it); | |
1088 } | |
1089 } | |
1090 | |
1091 CheckInvariants(); | |
1092 } | |
1093 | |
1094 | |
1095 bool JobsRegistry::GetState(JobState& state, | |
1096 const std::string& id) | |
1097 { | |
1098 boost::mutex::scoped_lock lock(mutex_); | |
2570
2e879c796ec7
JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
1099 return GetStateInternal(state, id); |
2569 | 1100 } |
1101 | |
2673
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1102 |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1103 void JobsRegistry::SetObserver(JobsRegistry::IObserver& observer) |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1104 { |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1105 boost::mutex::scoped_lock lock(mutex_); |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1106 observer_ = &observer; |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1107 } |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1108 |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1109 |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1110 void JobsRegistry::ResetObserver() |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1111 { |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1112 boost::mutex::scoped_lock lock(mutex_); |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1113 observer_ = NULL; |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1114 } |
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1115 |
2569 | 1116 |
1117 JobsRegistry::RunningJob::RunningJob(JobsRegistry& registry, | |
1118 unsigned int timeout) : | |
1119 registry_(registry), | |
1120 handler_(NULL), | |
1121 targetState_(JobState_Failure), | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1122 targetRetryTimeout_(0), |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1123 canceled_(false) |
2569 | 1124 { |
1125 { | |
1126 boost::mutex::scoped_lock lock(registry_.mutex_); | |
1127 | |
1128 while (registry_.pendingJobs_.empty()) | |
1129 { | |
1130 if (timeout == 0) | |
1131 { | |
1132 registry_.pendingJobAvailable_.wait(lock); | |
1133 } | |
1134 else | |
1135 { | |
1136 bool success = registry_.pendingJobAvailable_.timed_wait | |
1137 (lock, boost::posix_time::milliseconds(timeout)); | |
1138 if (!success) | |
1139 { | |
1140 // No pending job | |
1141 return; | |
1142 } | |
1143 } | |
1144 } | |
1145 | |
1146 handler_ = registry_.pendingJobs_.top(); | |
1147 registry_.pendingJobs_.pop(); | |
1148 | |
1149 assert(handler_->GetState() == JobState_Pending); | |
1150 handler_->SetState(JobState_Running); | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1151 handler_->SetLastErrorCode(ErrorCode_Success); |
2569 | 1152 |
1153 job_ = &handler_->GetJob(); | |
1154 id_ = handler_->GetId(); | |
1155 priority_ = handler_->GetPriority(); | |
1156 } | |
1157 } | |
1158 | |
1159 | |
1160 JobsRegistry::RunningJob::~RunningJob() | |
1161 { | |
1162 if (IsValid()) | |
1163 { | |
1164 boost::mutex::scoped_lock lock(registry_.mutex_); | |
1165 | |
1166 switch (targetState_) | |
1167 { | |
1168 case JobState_Failure: | |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1169 registry_.MarkRunningAsCompleted |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1170 (*handler_, canceled_ ? CompletedReason_Canceled : CompletedReason_Failure); |
2569 | 1171 break; |
1172 | |
1173 case JobState_Success: | |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1174 registry_.MarkRunningAsCompleted(*handler_, CompletedReason_Success); |
2569 | 1175 break; |
1176 | |
1177 case JobState_Paused: | |
1178 registry_.MarkRunningAsPaused(*handler_); | |
1179 break; | |
1180 | |
1181 case JobState_Retry: | |
1182 registry_.MarkRunningAsRetry(*handler_, targetRetryTimeout_); | |
1183 break; | |
1184 | |
1185 default: | |
1186 assert(0); | |
1187 } | |
1188 } | |
1189 } | |
1190 | |
1191 | |
1192 bool JobsRegistry::RunningJob::IsValid() const | |
1193 { | |
1194 return (handler_ != NULL && | |
1195 job_ != NULL); | |
1196 } | |
1197 | |
1198 | |
1199 const std::string& JobsRegistry::RunningJob::GetId() const | |
1200 { | |
1201 if (!IsValid()) | |
1202 { | |
1203 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1204 } | |
1205 else | |
1206 { | |
1207 return id_; | |
1208 } | |
1209 } | |
1210 | |
1211 | |
1212 int JobsRegistry::RunningJob::GetPriority() const | |
1213 { | |
1214 if (!IsValid()) | |
1215 { | |
1216 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1217 } | |
1218 else | |
1219 { | |
1220 return priority_; | |
1221 } | |
1222 } | |
1223 | |
1224 | |
1225 IJob& JobsRegistry::RunningJob::GetJob() | |
1226 { | |
1227 if (!IsValid()) | |
1228 { | |
1229 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1230 } | |
1231 else | |
1232 { | |
1233 return *job_; | |
1234 } | |
1235 } | |
1236 | |
1237 | |
1238 bool JobsRegistry::RunningJob::IsPauseScheduled() | |
1239 { | |
1240 if (!IsValid()) | |
1241 { | |
1242 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1243 } | |
1244 else | |
1245 { | |
1246 boost::mutex::scoped_lock lock(registry_.mutex_); | |
1247 registry_.CheckInvariants(); | |
1248 assert(handler_->GetState() == JobState_Running); | |
1249 | |
1250 return handler_->IsPauseScheduled(); | |
1251 } | |
1252 } | |
1253 | |
1254 | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1255 bool JobsRegistry::RunningJob::IsCancelScheduled() |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1256 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1257 if (!IsValid()) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1258 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1259 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1260 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1261 else |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1262 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1263 boost::mutex::scoped_lock lock(registry_.mutex_); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1264 registry_.CheckInvariants(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1265 assert(handler_->GetState() == JobState_Running); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1266 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1267 return handler_->IsCancelScheduled(); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1268 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1269 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1270 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1271 |
2569 | 1272 void JobsRegistry::RunningJob::MarkSuccess() |
1273 { | |
1274 if (!IsValid()) | |
1275 { | |
1276 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1277 } | |
1278 else | |
1279 { | |
1280 targetState_ = JobState_Success; | |
1281 } | |
1282 } | |
1283 | |
1284 | |
1285 void JobsRegistry::RunningJob::MarkFailure() | |
1286 { | |
1287 if (!IsValid()) | |
1288 { | |
1289 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1290 } | |
1291 else | |
1292 { | |
1293 targetState_ = JobState_Failure; | |
1294 } | |
1295 } | |
1296 | |
1297 | |
2581
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1298 void JobsRegistry::RunningJob::MarkCanceled() |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1299 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1300 if (!IsValid()) |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1301 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1302 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1303 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1304 else |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1305 { |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1306 targetState_ = JobState_Failure; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1307 canceled_ = true; |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1308 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1309 } |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1310 |
8da2cffc2378
JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2573
diff
changeset
|
1311 |
2569 | 1312 void JobsRegistry::RunningJob::MarkPause() |
1313 { | |
1314 if (!IsValid()) | |
1315 { | |
1316 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1317 } | |
1318 else | |
1319 { | |
1320 targetState_ = JobState_Paused; | |
1321 } | |
1322 } | |
1323 | |
1324 | |
1325 void JobsRegistry::RunningJob::MarkRetry(unsigned int timeout) | |
1326 { | |
1327 if (!IsValid()) | |
1328 { | |
1329 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1330 } | |
1331 else | |
1332 { | |
1333 targetState_ = JobState_Retry; | |
1334 targetRetryTimeout_ = timeout; | |
1335 } | |
1336 } | |
1337 | |
1338 | |
3240
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
1339 void JobsRegistry::RunningJob::UpdateStatus(ErrorCode code, |
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
1340 const std::string& details) |
2569 | 1341 { |
1342 if (!IsValid()) | |
1343 { | |
1344 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1345 } | |
1346 else | |
1347 { | |
3240
e44e0127e553
Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3191
diff
changeset
|
1348 JobStatus status(code, details, *job_); |
2569 | 1349 |
1350 boost::mutex::scoped_lock lock(registry_.mutex_); | |
1351 registry_.CheckInvariants(); | |
1352 assert(handler_->GetState() == JobState_Running); | |
1353 | |
1354 handler_->SetLastStatus(status); | |
1355 } | |
1356 } | |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1357 |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1358 |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1359 |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1360 void JobsRegistry::Serialize(Json::Value& target) |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1361 { |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1362 boost::mutex::scoped_lock lock(mutex_); |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1363 CheckInvariants(); |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1364 |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1365 target = Json::objectValue; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1366 target[TYPE] = JOBS_REGISTRY; |
2670
c5646f766b3e
serialize jobs as an object
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2669
diff
changeset
|
1367 target[JOBS] = Json::objectValue; |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1368 |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1369 for (JobsIndex::const_iterator it = jobsIndex_.begin(); |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1370 it != jobsIndex_.end(); ++it) |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1371 { |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1372 Json::Value v; |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1373 if (it->second->Serialize(v)) |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1374 { |
2670
c5646f766b3e
serialize jobs as an object
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2669
diff
changeset
|
1375 target[JOBS][it->first] = v; |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1376 } |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1377 } |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1378 } |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1379 |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1380 |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1381 JobsRegistry::JobsRegistry(IJobUnserializer& unserializer, |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1382 const Json::Value& s, |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1383 size_t maxCompletedJobs) : |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1384 maxCompletedJobs_(maxCompletedJobs), |
2673
8e0bc055d18c
JobsRegistry::IObserver
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2670
diff
changeset
|
1385 observer_(NULL) |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1386 { |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1387 if (SerializationToolbox::ReadString(s, TYPE) != JOBS_REGISTRY || |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1388 !s.isMember(JOBS) || |
2670
c5646f766b3e
serialize jobs as an object
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2669
diff
changeset
|
1389 s[JOBS].type() != Json::objectValue) |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1390 { |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1391 throw OrthancException(ErrorCode_BadFileFormat); |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1392 } |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1393 |
2670
c5646f766b3e
serialize jobs as an object
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2669
diff
changeset
|
1394 Json::Value::Members members = s[JOBS].getMemberNames(); |
c5646f766b3e
serialize jobs as an object
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2669
diff
changeset
|
1395 |
c5646f766b3e
serialize jobs as an object
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2669
diff
changeset
|
1396 for (Json::Value::Members::const_iterator it = members.begin(); |
c5646f766b3e
serialize jobs as an object
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2669
diff
changeset
|
1397 it != members.end(); ++it) |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1398 { |
3191
20826867141f
ignore jobs that cannot be unserialized
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3179
diff
changeset
|
1399 std::auto_ptr<JobHandler> job; |
20826867141f
ignore jobs that cannot be unserialized
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3179
diff
changeset
|
1400 |
20826867141f
ignore jobs that cannot be unserialized
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3179
diff
changeset
|
1401 try |
20826867141f
ignore jobs that cannot be unserialized
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3179
diff
changeset
|
1402 { |
20826867141f
ignore jobs that cannot be unserialized
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3179
diff
changeset
|
1403 job.reset(new JobHandler(unserializer, s[JOBS][*it], *it)); |
20826867141f
ignore jobs that cannot be unserialized
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3179
diff
changeset
|
1404 } |
20826867141f
ignore jobs that cannot be unserialized
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3179
diff
changeset
|
1405 catch (OrthancException& e) |
20826867141f
ignore jobs that cannot be unserialized
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3179
diff
changeset
|
1406 { |
20826867141f
ignore jobs that cannot be unserialized
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3179
diff
changeset
|
1407 LOG(WARNING) << "Cannot unserialize one job from previous execution, " |
20826867141f
ignore jobs that cannot be unserialized
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3179
diff
changeset
|
1408 << "skipping it: " << e.What(); |
20826867141f
ignore jobs that cannot be unserialized
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3179
diff
changeset
|
1409 continue; |
20826867141f
ignore jobs that cannot be unserialized
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3179
diff
changeset
|
1410 } |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1411 |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1412 const boost::posix_time::ptime lastChangeTime = job->GetLastStateChangeTime(); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1413 |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1414 std::string id; |
2950
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1415 SubmitInternal(id, job.release()); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1416 |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1417 // Check whether the job has not been removed (which could be |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1418 // the case if the "maxCompletedJobs_" value gets smaller) |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1419 JobsIndex::iterator found = jobsIndex_.find(id); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1420 if (found != jobsIndex_.end()) |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1421 { |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1422 // The job still lies in the history: Update the time of its |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1423 // last change to the time that was serialized |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1424 assert(found->second != NULL); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1425 found->second->SetLastStateChangeTime(lastChangeTime); |
dc18d5804746
support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2939
diff
changeset
|
1426 } |
2667
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1427 } |
5fa2f2ce74f0
serialization of JobsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2663
diff
changeset
|
1428 } |
3177
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1429 |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1430 |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1431 void JobsRegistry::GetStatistics(unsigned int& pending, |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1432 unsigned int& running, |
3179
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3177
diff
changeset
|
1433 unsigned int& success, |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3177
diff
changeset
|
1434 unsigned int& failed) |
3177
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1435 { |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1436 boost::mutex::scoped_lock lock(mutex_); |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1437 CheckInvariants(); |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1438 |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1439 pending = 0; |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1440 running = 0; |
3179
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3177
diff
changeset
|
1441 success = 0; |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3177
diff
changeset
|
1442 failed = 0; |
3177
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1443 |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1444 for (JobsIndex::const_iterator it = jobsIndex_.begin(); |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1445 it != jobsIndex_.end(); ++it) |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1446 { |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1447 JobHandler& job = *it->second; |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1448 |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1449 switch (job.GetState()) |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1450 { |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1451 case JobState_Retry: |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1452 case JobState_Pending: |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1453 pending ++; |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1454 break; |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1455 |
3179
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3177
diff
changeset
|
1456 case JobState_Paused: |
3177
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1457 case JobState_Running: |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1458 running ++; |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1459 break; |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1460 |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1461 case JobState_Success: |
3179
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3177
diff
changeset
|
1462 success ++; |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3177
diff
changeset
|
1463 break; |
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3177
diff
changeset
|
1464 |
3177
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1465 case JobState_Failure: |
3179
fca730c267d7
New primitives to set and refresh metrics
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3177
diff
changeset
|
1466 failed ++; |
3177
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1467 break; |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1468 |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1469 default: |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1470 throw OrthancException(ErrorCode_InternalError); |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1471 } |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1472 } |
053e72ff9fc5
new metrics: orthanc_jobs_[pending|running|completed]
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3162
diff
changeset
|
1473 } |
2569 | 1474 } |