Mercurial > hg > orthanc
annotate Core/JobsEngine/JobInfo.cpp @ 3056:6c5d4281da4a db-changes
removal of SQLiteDatabaseWrapper::GetAllInternalIds
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 21 Dec 2018 13:48:04 +0100 |
parents | 73d7d95dd75e |
children | 4e43e67f8ecf |
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 | |
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../PrecompiledHeaders.h" | |
35 #include "JobInfo.h" | |
36 | |
37 #include "../OrthancException.h" | |
38 | |
2593 | 39 // This "include" is mandatory for Release builds using Linux Standard Base |
40 #include <boost/math/special_functions/round.hpp> | |
41 | |
2569 | 42 namespace Orthanc |
43 { | |
44 JobInfo::JobInfo(const std::string& id, | |
45 int priority, | |
46 JobState state, | |
47 const JobStatus& status, | |
48 const boost::posix_time::ptime& creationTime, | |
49 const boost::posix_time::ptime& lastStateChangeTime, | |
50 const boost::posix_time::time_duration& runtime) : | |
51 id_(id), | |
52 priority_(priority), | |
53 state_(state), | |
54 timestamp_(boost::posix_time::microsec_clock::universal_time()), | |
55 creationTime_(creationTime), | |
56 lastStateChangeTime_(lastStateChangeTime), | |
57 runtime_(runtime), | |
58 hasEta_(false), | |
59 status_(status) | |
60 { | |
61 if (state_ == JobState_Running) | |
62 { | |
63 float ms = static_cast<float>(runtime_.total_milliseconds()); | |
64 | |
65 if (status_.GetProgress() > 0.01f && | |
66 ms > 0.01f) | |
67 { | |
2573
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
68 float ratio = static_cast<float>(1.0 - status_.GetProgress()); |
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
69 long long remaining = boost::math::llround(ratio * ms); |
2569 | 70 eta_ = timestamp_ + boost::posix_time::milliseconds(remaining); |
71 hasEta_ = true; | |
72 } | |
73 } | |
74 } | |
75 | |
76 | |
77 JobInfo::JobInfo() : | |
78 priority_(0), | |
79 state_(JobState_Failure), | |
80 timestamp_(boost::posix_time::microsec_clock::universal_time()), | |
81 creationTime_(timestamp_), | |
82 lastStateChangeTime_(timestamp_), | |
83 runtime_(boost::posix_time::milliseconds(0)), | |
84 hasEta_(false) | |
85 { | |
86 } | |
87 | |
88 | |
89 bool JobInfo::HasCompletionTime() const | |
90 { | |
91 return (state_ == JobState_Success || | |
92 state_ == JobState_Failure); | |
93 } | |
94 | |
95 | |
96 const boost::posix_time::ptime& JobInfo::GetEstimatedTimeOfArrival() const | |
97 { | |
98 if (hasEta_) | |
99 { | |
100 return eta_; | |
101 } | |
102 else | |
103 { | |
104 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
105 } | |
106 } | |
107 | |
108 | |
109 const boost::posix_time::ptime& JobInfo::GetCompletionTime() const | |
110 { | |
111 if (HasCompletionTime()) | |
112 { | |
113 return lastStateChangeTime_; | |
114 } | |
115 else | |
116 { | |
117 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
118 } | |
119 } | |
120 | |
121 | |
2647
73d7d95dd75e
removal of internal job information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2593
diff
changeset
|
122 void JobInfo::Format(Json::Value& target) const |
2569 | 123 { |
124 target = Json::objectValue; | |
125 target["ID"] = id_; | |
126 target["Priority"] = priority_; | |
127 target["ErrorCode"] = static_cast<int>(status_.GetErrorCode()); | |
128 target["ErrorDescription"] = EnumerationToString(status_.GetErrorCode()); | |
129 target["State"] = EnumerationToString(state_); | |
130 target["Timestamp"] = boost::posix_time::to_iso_string(timestamp_); | |
131 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
|
132 target["EffectiveRuntime"] = static_cast<double>(runtime_.total_milliseconds()) / 1000.0; |
2569 | 133 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
|
134 |
3372c5255333
StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2569
diff
changeset
|
135 target["Type"] = status_.GetJobType(); |
2647
73d7d95dd75e
removal of internal job information
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2593
diff
changeset
|
136 target["Content"] = status_.GetPublicContent(); |
2569 | 137 |
138 if (HasEstimatedTimeOfArrival()) | |
139 { | |
140 target["EstimatedTimeOfArrival"] = boost::posix_time::to_iso_string(GetEstimatedTimeOfArrival()); | |
141 } | |
142 | |
143 if (HasCompletionTime()) | |
144 { | |
145 target["CompletionTime"] = boost::posix_time::to_iso_string(GetCompletionTime()); | |
146 } | |
147 } | |
148 } |