comparison Core/JobsEngine/SetOfInstancesJob.cpp @ 2586:ec09641d6f41 jobs

simplifications
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 14 May 2018 21:33:57 +0200
parents 4c809711149e
children 34dc57f4a7d2
comparison
equal deleted inserted replaced
2585:4c809711149e 2586:ec09641d6f41
111 static_cast<float>(instances_.size())); 111 static_cast<float>(instances_.size()));
112 } 112 }
113 } 113 }
114 114
115 115
116 void SetOfInstancesJob::Next()
117 {
118 if (IsDone())
119 {
120 throw OrthancException(ErrorCode_BadSequenceOfCalls);
121 }
122 else
123 {
124 position_ += 1;
125 }
126 }
127
128
129 const std::string& SetOfInstancesJob::GetCurrentInstance() const
130 {
131 if (IsDone())
132 {
133 throw OrthancException(ErrorCode_BadSequenceOfCalls);
134 }
135 else
136 {
137 return instances_[position_];
138 }
139 }
140
141
142 JobStepResult* SetOfInstancesJob::ExecuteStep() 116 JobStepResult* SetOfInstancesJob::ExecuteStep()
143 { 117 {
144 if (IsDone()) 118 if (!started_)
145 { 119 {
120 throw OrthancException(ErrorCode_InternalError);
121 }
122
123 if (instances_.empty() &&
124 position_ == 0)
125 {
126 // No instance to handle, we're done
127 position_ = 1;
128 return new JobStepResult(JobStepCode_Success);
129 }
130
131 if (position_ >= instances_.size())
132 {
133 // Already done
146 return new JobStepResult(JobStepCode_Failure); 134 return new JobStepResult(JobStepCode_Failure);
147 } 135 }
148 136
137 const std::string currentInstance = instances_[position_];
138
149 bool ok; 139 bool ok;
150 140
151 try 141 try
152 { 142 {
153 ok = HandleInstance(GetCurrentInstance()); 143 ok = HandleInstance(currentInstance);
154 144
155 if (!ok && !permissive_) 145 if (!ok && !permissive_)
156 { 146 {
157 throw OrthancException(ErrorCode_InternalError); 147 throw OrthancException(ErrorCode_InternalError);
158 } 148 }
169 } 159 }
170 } 160 }
171 161
172 if (!ok) 162 if (!ok)
173 { 163 {
174 failedInstances_.insert(GetCurrentInstance()); 164 failedInstances_.insert(currentInstance);
175 } 165 }
176 166
177 Next(); 167 position_ += 1;
178 168
179 if (IsDone()) 169 if (position_ == instances_.size())
180 { 170 {
171 // We're done
181 return new JobStepResult(JobStepCode_Success); 172 return new JobStepResult(JobStepCode_Success);
182 } 173 }
183 else 174 else
184 { 175 {
185 return new JobStepResult(JobStepCode_Continue); 176 return new JobStepResult(JobStepCode_Continue);