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