comparison OrthancServer/Scheduler/ServerScheduler.cpp @ 995:8c67382f44a7 lua-scripting

limit number of jobs in the scheduler
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 03 Jul 2014 15:58:53 +0200
parents c9cdd53a6b31
children db18c071fbd7
comparison
equal deleted inserted replaced
994:b3d4f8a30324 995:8c67382f44a7
96 if (info.success_ >= info.size_) 96 if (info.success_ >= info.size_)
97 { 97 {
98 if (info.watched_) 98 if (info.watched_)
99 { 99 {
100 watchedJobStatus_[jobId] = JobStatus_Success; 100 watchedJobStatus_[jobId] = JobStatus_Success;
101 jobFinished_.notify_all(); 101 watchedJobFinished_.notify_all();
102 } 102 }
103 103
104 LOG(INFO) << "Job successfully finished (" << info.description_ << ")"; 104 LOG(INFO) << "Job successfully finished (" << info.description_ << ")";
105 jobs_.erase(jobId); 105 jobs_.erase(jobId);
106
107 availableJob_.Release();
106 } 108 }
107 } 109 }
108 110
109 111
110 void ServerScheduler::SignalFailure(const std::string& jobId) 112 void ServerScheduler::SignalFailure(const std::string& jobId)
117 if (info.success_ + info.failures_ >= info.size_) 119 if (info.success_ + info.failures_ >= info.size_)
118 { 120 {
119 if (info.watched_) 121 if (info.watched_)
120 { 122 {
121 watchedJobStatus_[jobId] = JobStatus_Failure; 123 watchedJobStatus_[jobId] = JobStatus_Failure;
122 jobFinished_.notify_all(); 124 watchedJobFinished_.notify_all();
123 } 125 }
124 126
125 LOG(ERROR) << "Job has failed (" << info.description_ << ")"; 127 LOG(ERROR) << "Job has failed (" << info.description_ << ")";
126 jobs_.erase(jobId); 128 jobs_.erase(jobId);
129
130 availableJob_.Release();
127 } 131 }
128 } 132 }
129 133
130 134
131 void ServerScheduler::Worker(ServerScheduler* that) 135 void ServerScheduler::Worker(ServerScheduler* that)
164 168
165 169
166 void ServerScheduler::SubmitInternal(ServerJob& job, 170 void ServerScheduler::SubmitInternal(ServerJob& job,
167 bool watched) 171 bool watched)
168 { 172 {
173 availableJob_.Acquire();
174
169 boost::mutex::scoped_lock lock(mutex_); 175 boost::mutex::scoped_lock lock(mutex_);
170 176
171 JobInfo info; 177 JobInfo info;
172 info.size_ = job.Submit(queue_, *this); 178 info.size_ = job.Submit(queue_, *this);
173 info.cancel_ = false; 179 info.cancel_ = false;
187 193
188 LOG(INFO) << "New job submitted (" << job.description_ << ")"; 194 LOG(INFO) << "New job submitted (" << job.description_ << ")";
189 } 195 }
190 196
191 197
192 ServerScheduler::ServerScheduler() 198 ServerScheduler::ServerScheduler(unsigned int maxJobs) : availableJob_(maxJobs)
193 { 199 {
194 finish_ = false; 200 finish_ = false;
195 worker_ = boost::thread(Worker, this); 201 worker_ = boost::thread(Worker, this);
196 } 202 }
197 203
252 258
253 assert(watchedJobStatus_.find(jobId) != watchedJobStatus_.end()); 259 assert(watchedJobStatus_.find(jobId) != watchedJobStatus_.end());
254 260
255 while (watchedJobStatus_[jobId] == JobStatus_Running) 261 while (watchedJobStatus_[jobId] == JobStatus_Running)
256 { 262 {
257 jobFinished_.wait(lock); 263 watchedJobFinished_.wait(lock);
258 } 264 }
259 265
260 status = watchedJobStatus_[jobId]; 266 status = watchedJobStatus_[jobId];
261 watchedJobStatus_.erase(jobId); 267 watchedJobStatus_.erase(jobId);
262 } 268 }