Mercurial > hg > orthanc
annotate OrthancFramework/Sources/JobsEngine/JobInfo.cpp @ 4845:02d77189d8ba received-instance-callback
added ReceivedInstanceCallback + sample C++ plugin
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 09 Dec 2021 17:22:40 +0100 |
parents | 7053502fbf97 |
children | 43e613a7756b |
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 | |
4437
d9473bd5ed43
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
4831
7053502fbf97
added copyright UCLouvain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4767
diff
changeset
|
6 * Copyright (C) 2021-2021 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. |
2569 | 12 * |
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" | |
3585
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
25 |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
26 #ifdef __EMSCRIPTEN__ |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
27 /* |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
28 Avoid this error: |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
29 |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
30 .../boost/math/special_functions/round.hpp:118:12: warning: implicit conversion from 'std::__2::numeric_limits<long long>::type' (aka 'long long') to 'float' changes value from 9223372036854775807 to 9223372036854775808 [-Wimplicit-int-float-conversion] |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
31 .../boost/math/special_functions/round.hpp:125:11: note: in instantiation of function template specialization 'boost::math::llround<float, boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> >' requested here |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
32 .../orthanc/Core/JobsEngine/JobInfo.cpp:69:44: note: in instantiation of function template specialization 'boost::math::llround<float>' requested here |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
33 |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
34 .../boost/math/special_functions/round.hpp:86:12: warning: implicit conversion from 'std::__2::numeric_limits<int>::type' (aka 'int') to 'float' changes value from 2147483647 to 2147483648 [-Wimplicit-int-float-conversion] |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
35 .../boost/math/special_functions/round.hpp:93:11: note: in instantiation of function template specialization 'boost::math::iround<float, boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy> >' requested here |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
36 .../orthanc/Core/JobsEngine/JobInfo.cpp:133:39: note: in instantiation of function template specialization 'boost::math::iround<float>' requested here |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
37 */ |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
38 #pragma GCC diagnostic ignored "-Wimplicit-int-float-conversion" |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
39 #endif |
113a9643e8bb
Suppressed a few warnings when building with emscripten (clang) + numeric truncation warnings
Benjamin Golinvaux <bgo@osimis.io>
parents:
3060
diff
changeset
|
40 |
2569 | 41 #include "JobInfo.h" |
42 | |
43 #include "../OrthancException.h" | |
44 | |
2593 | 45 // This "include" is mandatory for Release builds using Linux Standard Base |
46 #include <boost/math/special_functions/round.hpp> | |
47 | |
2569 | 48 namespace Orthanc |
49 { | |
50 JobInfo::JobInfo(const std::string& id, | |
51 int priority, | |
52 JobState state, | |
53 const JobStatus& status, | |
54 const boost::posix_time::ptime& creationTime, | |
55 const boost::posix_time::ptime& lastStateChangeTime, | |
56 const boost::posix_time::time_duration& runtime) : | |
57 id_(id), | |
58 priority_(priority), | |
59 state_(state), | |
60 timestamp_(boost::posix_time::microsec_clock::universal_time()), | |
61 creationTime_(creationTime), | |
62 lastStateChangeTime_(lastStateChangeTime), | |
63 runtime_(runtime), | |
64 hasEta_(false), | |
65 status_(status) | |
66 { | |
67 if (state_ == JobState_Running) | |
68 { | |
69 float ms = static_cast<float>(runtime_.total_milliseconds()); | |
70 | |
71 if (status_.GetProgress() > 0.01f && | |
72 ms > 0.01f) | |
73 { | |
4767
e1711b6e141f
Fix computation of the estimated time of arrival in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4667
diff
changeset
|
74 float progress = status_.GetProgress(); |
e1711b6e141f
Fix computation of the estimated time of arrival in jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4667
diff
changeset
|
75 long long remaining = boost::math::llround(ms / progress * (1.0f - progress)); |
2569 | 76 eta_ = timestamp_ + boost::posix_time::milliseconds(remaining); |
77 hasEta_ = true; | |
78 } | |
79 } | |
80 } | |
81 | |
82 | |
83 JobInfo::JobInfo() : | |
84 priority_(0), | |
85 state_(JobState_Failure), | |
86 timestamp_(boost::posix_time::microsec_clock::universal_time()), | |
87 creationTime_(timestamp_), | |
88 lastStateChangeTime_(timestamp_), | |
89 runtime_(boost::posix_time::milliseconds(0)), | |
90 hasEta_(false) | |
91 { | |
92 } | |
93 | |
4300 | 94 const std::string &JobInfo::GetIdentifier() const |
95 { | |
96 return id_; | |
97 } | |
98 | |
99 int JobInfo::GetPriority() const | |
100 { | |
101 return priority_; | |
102 } | |
103 | |
104 JobState JobInfo::GetState() const | |
105 { | |
106 return state_; | |
107 } | |
108 | |
109 const boost::posix_time::ptime &JobInfo::GetInfoTime() const | |
110 { | |
111 return timestamp_; | |
112 } | |
113 | |
114 const boost::posix_time::ptime &JobInfo::GetCreationTime() const | |
115 { | |
116 return creationTime_; | |
117 } | |
118 | |
119 const boost::posix_time::time_duration &JobInfo::GetRuntime() const | |
120 { | |
121 return runtime_; | |
122 } | |
123 | |
124 bool JobInfo::HasEstimatedTimeOfArrival() const | |
125 { | |
126 return hasEta_; | |
127 } | |
128 | |
2569 | 129 |
130 bool JobInfo::HasCompletionTime() const | |
131 { | |
132 return (state_ == JobState_Success || | |
133 state_ == JobState_Failure); | |
134 } | |
135 | |
136 | |
137 const boost::posix_time::ptime& JobInfo::GetEstimatedTimeOfArrival() const | |
138 { | |
139 if (hasEta_) | |
140 { | |
141 return eta_; | |
142 } | |
143 else | |
144 { | |
145 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
146 } | |
147 } | |
148 | |
149 | |
150 const boost::posix_time::ptime& JobInfo::GetCompletionTime() const | |
151 { | |
152 if (HasCompletionTime()) | |
153 { | |
154 return lastStateChangeTime_; | |
155 } | |
156 else | |
157 { | |
158 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
159 } | |
160 } | |
161 | |
4300 | 162 const JobStatus &JobInfo::GetStatus() const |
163 { | |
164 return status_; | |
165 } | |
166 | |
167 JobStatus &JobInfo::GetStatus() | |
168 { | |
169 return status_; | |
170 } | |
171 | |
2569 | 172 |
2647
73d7d95dd75e
removal of internal job information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2593
diff
changeset
|
173 void JobInfo::Format(Json::Value& target) const |
2569 | 174 { |
175 target = Json::objectValue; | |
176 target["ID"] = id_; | |
177 target["Priority"] = priority_; | |
178 target["ErrorCode"] = static_cast<int>(status_.GetErrorCode()); | |
179 target["ErrorDescription"] = EnumerationToString(status_.GetErrorCode()); | |
4667
08ee98bf103e
"/jobs/..." has new field "ErrorDetails" to help identify the cause of an error
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
180 target["ErrorDetails"] = status_.GetDetails(); |
2569 | 181 target["State"] = EnumerationToString(state_); |
182 target["Timestamp"] = boost::posix_time::to_iso_string(timestamp_); | |
183 target["CreationTime"] = boost::posix_time::to_iso_string(creationTime_); | |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
184 target["EffectiveRuntime"] = static_cast<double>(runtime_.total_milliseconds()) / 1000.0; |
2569 | 185 target["Progress"] = boost::math::iround(status_.GetProgress() * 100.0f); |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
186 |
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
187 target["Type"] = status_.GetJobType(); |
2647
73d7d95dd75e
removal of internal job information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2593
diff
changeset
|
188 target["Content"] = status_.GetPublicContent(); |
2569 | 189 |
190 if (HasEstimatedTimeOfArrival()) | |
191 { | |
192 target["EstimatedTimeOfArrival"] = boost::posix_time::to_iso_string(GetEstimatedTimeOfArrival()); | |
193 } | |
194 | |
195 if (HasCompletionTime()) | |
196 { | |
197 target["CompletionTime"] = boost::posix_time::to_iso_string(GetCompletionTime()); | |
198 } | |
199 } | |
200 } |