Mercurial > hg > orthanc
comparison Core/JobsEngine/JobsRegistry.h @ 4027:3a77d4073adf
merge
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 09 Jun 2020 16:33:08 +0200 |
parents | 1d2b31fc782f |
children |
comparison
equal
deleted
inserted
replaced
4026:05a363186da6 | 4027:3a77d4073adf |
---|---|
18 * modify file(s) with this exception, you may extend this exception to | 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 | 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 | 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 | 21 * version. If you delete this exception statement from all source files |
22 * in the program, then also delete it here. | 22 * in the program, then also delete it here. |
23 * | 23 * |
24 * This program is distributed in the hope that it will be useful, but | 24 * This program is distributed in the hope that it will be useful, but |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | 25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
27 * General Public License for more details. | 27 * General Public License for more details. |
28 * | 28 * |
67 | 67 |
68 virtual void SignalJobSuccess(const std::string& jobId) = 0; | 68 virtual void SignalJobSuccess(const std::string& jobId) = 0; |
69 | 69 |
70 virtual void SignalJobFailure(const std::string& jobId) = 0; | 70 virtual void SignalJobFailure(const std::string& jobId) = 0; |
71 }; | 71 }; |
72 | 72 |
73 private: | 73 private: |
74 enum CompletedReason | 74 enum CompletedReason |
75 { | 75 { |
76 CompletedReason_Success, | 76 CompletedReason_Success, |
77 CompletedReason_Failure, | 77 CompletedReason_Failure, |
78 CompletedReason_Canceled | 78 CompletedReason_Canceled |
79 }; | 79 }; |
80 | 80 |
81 class JobHandler; | 81 class JobHandler; |
82 | 82 |
83 struct PriorityComparator | 83 struct PriorityComparator |
84 { | 84 { |
85 bool operator() (JobHandler*& a, | 85 bool operator() (JobHandler*& a, |
87 }; | 87 }; |
88 | 88 |
89 typedef std::map<std::string, JobHandler*> JobsIndex; | 89 typedef std::map<std::string, JobHandler*> JobsIndex; |
90 typedef std::list<JobHandler*> CompletedJobs; | 90 typedef std::list<JobHandler*> CompletedJobs; |
91 typedef std::set<JobHandler*> RetryJobs; | 91 typedef std::set<JobHandler*> RetryJobs; |
92 typedef std::priority_queue<JobHandler*, | 92 typedef std::priority_queue<JobHandler*, |
93 std::vector<JobHandler*>, // Could be a "std::deque" | 93 std::vector<JobHandler*>, // Could be a "std::deque" |
94 PriorityComparator> PendingJobs; | 94 PriorityComparator> PendingJobs; |
95 | 95 |
96 boost::mutex mutex_; | 96 boost::mutex mutex_; |
97 JobsIndex jobsIndex_; | 97 JobsIndex jobsIndex_; |
108 | 108 |
109 #ifndef NDEBUG | 109 #ifndef NDEBUG |
110 bool IsPendingJob(const JobHandler& job) const; | 110 bool IsPendingJob(const JobHandler& job) const; |
111 | 111 |
112 bool IsCompletedJob(JobHandler& job) const; | 112 bool IsCompletedJob(JobHandler& job) const; |
113 | 113 |
114 bool IsRetryJob(JobHandler& job) const; | 114 bool IsRetryJob(JobHandler& job) const; |
115 #endif | 115 #endif |
116 | 116 |
117 void CheckInvariants() const; | 117 void CheckInvariants() const; |
118 | 118 |
119 void ForgetOldCompletedJobs(); | 119 void ForgetOldCompletedJobs(); |
120 | 120 |
121 void SetCompletedJob(JobHandler& job, | 121 void SetCompletedJob(JobHandler& job, |
122 bool success); | 122 bool success); |
123 | 123 |
124 void MarkRunningAsCompleted(JobHandler& job, | 124 void MarkRunningAsCompleted(JobHandler& job, |
125 CompletedReason reason); | 125 CompletedReason reason); |
126 | 126 |
127 void MarkRunningAsRetry(JobHandler& job, | 127 void MarkRunningAsRetry(JobHandler& job, |
128 unsigned int timeout); | 128 unsigned int timeout); |
129 | 129 |
130 void MarkRunningAsPaused(JobHandler& job); | 130 void MarkRunningAsPaused(JobHandler& job); |
131 | 131 |
132 bool GetStateInternal(JobState& state, | 132 bool GetStateInternal(JobState& state, |
133 const std::string& id); | 133 const std::string& id); |
134 | 134 |
135 void RemovePendingJob(const std::string& id); | 135 void RemovePendingJob(const std::string& id); |
136 | 136 |
137 void RemoveRetryJob(JobHandler* handler); | 137 void RemoveRetryJob(JobHandler* handler); |
138 | 138 |
139 void SubmitInternal(std::string& id, | 139 void SubmitInternal(std::string& id, |
140 JobHandler* handler); | 140 JobHandler* handler); |
141 | 141 |
142 public: | 142 public: |
143 JobsRegistry(size_t maxCompletedJobs) : | 143 JobsRegistry(size_t maxCompletedJobs) : |
144 maxCompletedJobs_(maxCompletedJobs), | 144 maxCompletedJobs_(maxCompletedJobs), |
145 observer_(NULL) | 145 observer_(NULL) |
146 { | 146 { |
151 size_t maxCompletedJobs); | 151 size_t maxCompletedJobs); |
152 | 152 |
153 ~JobsRegistry(); | 153 ~JobsRegistry(); |
154 | 154 |
155 void SetMaxCompletedJobs(size_t i); | 155 void SetMaxCompletedJobs(size_t i); |
156 | 156 |
157 size_t GetMaxCompletedJobs(); | 157 size_t GetMaxCompletedJobs(); |
158 | 158 |
159 void ListJobs(std::set<std::string>& target); | 159 void ListJobs(std::set<std::string>& target); |
160 | 160 |
161 bool GetJobInfo(JobInfo& target, | 161 bool GetJobInfo(JobInfo& target, |
165 MimeType& mime, | 165 MimeType& mime, |
166 const std::string& job, | 166 const std::string& job, |
167 const std::string& key); | 167 const std::string& key); |
168 | 168 |
169 void Serialize(Json::Value& target); | 169 void Serialize(Json::Value& target); |
170 | 170 |
171 void Submit(std::string& id, | 171 void Submit(std::string& id, |
172 IJob* job, // Takes ownership | 172 IJob* job, // Takes ownership |
173 int priority); | 173 int priority); |
174 | 174 |
175 void Submit(IJob* job, // Takes ownership | 175 void Submit(IJob* job, // Takes ownership |
176 int priority); | 176 int priority); |
177 | 177 |
178 void SubmitAndWait(Json::Value& successContent, | 178 void SubmitAndWait(Json::Value& successContent, |
179 IJob* job, // Takes ownership | 179 IJob* job, // Takes ownership |
180 int priority); | 180 int priority); |
181 | 181 |
182 bool SetPriority(const std::string& id, | 182 bool SetPriority(const std::string& id, |
183 int priority); | 183 int priority); |
184 | 184 |
185 bool Pause(const std::string& id); | 185 bool Pause(const std::string& id); |
186 | 186 |
187 bool Resume(const std::string& id); | 187 bool Resume(const std::string& id); |
188 | 188 |
189 bool Resubmit(const std::string& id); | 189 bool Resubmit(const std::string& id); |
190 | 190 |
191 bool Cancel(const std::string& id); | 191 bool Cancel(const std::string& id); |
192 | 192 |
193 void ScheduleRetries(); | 193 void ScheduleRetries(); |
194 | 194 |
195 bool GetState(JobState& state, | 195 bool GetState(JobState& state, |
196 const std::string& id); | 196 const std::string& id); |
197 | 197 |
198 void SetObserver(IObserver& observer); | 198 void SetObserver(IObserver& observer); |
199 | 199 |
217 std::string id_; | 217 std::string id_; |
218 int priority_; | 218 int priority_; |
219 JobState targetState_; | 219 JobState targetState_; |
220 unsigned int targetRetryTimeout_; | 220 unsigned int targetRetryTimeout_; |
221 bool canceled_; | 221 bool canceled_; |
222 | 222 |
223 public: | 223 public: |
224 RunningJob(JobsRegistry& registry, | 224 RunningJob(JobsRegistry& registry, |
225 unsigned int timeout); | 225 unsigned int timeout); |
226 | 226 |
227 ~RunningJob(); | 227 ~RunningJob(); |