annotate OrthancServer/Scheduler/ServerScheduler.cpp @ 2294:e371519d4ac9

added -U option to gdcmconv to prevent gdcmconv to mess up the files. Without that option, we have seen the SpecificCharSet tag becoming invalid !!! (seen on the VIX samples)
author Alain Mazy <am@osimis.io>
date Tue, 04 Jul 2017 15:36:19 +0000
parents a3a65de1840f
children 878b59270859
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1624
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1009
diff changeset
4 * Department, University Hospital of Liege, Belgium
2244
a3a65de1840f shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2223
diff changeset
5 * Copyright (C) 2017 Osimis, Belgium
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
1624
0a2ad4a6858f fix missing precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1545
diff changeset
34 #include "../PrecompiledHeadersServer.h"
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "ServerScheduler.h"
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../../Core/OrthancException.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1453
diff changeset
38 #include "../../Core/Logging.h"
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 namespace Orthanc
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 namespace
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 // Anonymous namespace to avoid clashes between compilation modules
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
45 class Sink : public IServerCommand
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 private:
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 ListOfStrings& target_;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 public:
2223
29689b30f9ae cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2063
diff changeset
51 explicit Sink(ListOfStrings& target) : target_(target)
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 virtual bool Apply(ListOfStrings& outputs,
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 const ListOfStrings& inputs)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 for (ListOfStrings::const_iterator
1304
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
59 it = inputs.begin(); it != inputs.end(); ++it)
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 target_.push_back(*it);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 return true;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 };
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 ServerScheduler::JobInfo& ServerScheduler::GetJobInfo(const std::string& jobId)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 Jobs::iterator info = jobs_.find(jobId);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 if (info == jobs_.end())
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 throw OrthancException(ErrorCode_InternalError);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 return info->second;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 void ServerScheduler::SignalSuccess(const std::string& jobId)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 boost::mutex::scoped_lock lock(mutex_);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 JobInfo& info = GetJobInfo(jobId);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 info.success_++;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 assert(info.failures_ == 0);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 if (info.success_ >= info.size_)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 if (info.watched_)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 watchedJobStatus_[jobId] = JobStatus_Success;
995
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 783
diff changeset
97 watchedJobFinished_.notify_all();
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 LOG(INFO) << "Job successfully finished (" << info.description_ << ")";
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 jobs_.erase(jobId);
995
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 783
diff changeset
102
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 783
diff changeset
103 availableJob_.Release();
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 void ServerScheduler::SignalFailure(const std::string& jobId)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 boost::mutex::scoped_lock lock(mutex_);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 JobInfo& info = GetJobInfo(jobId);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 info.failures_++;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 if (info.success_ + info.failures_ >= info.size_)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 if (info.watched_)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 watchedJobStatus_[jobId] = JobStatus_Failure;
995
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 783
diff changeset
120 watchedJobFinished_.notify_all();
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 LOG(ERROR) << "Job has failed (" << info.description_ << ")";
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 jobs_.erase(jobId);
995
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 783
diff changeset
125
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 783
diff changeset
126 availableJob_.Release();
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 void ServerScheduler::Worker(ServerScheduler* that)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 static const int32_t TIMEOUT = 100;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
783
c9cdd53a6b31 main scheduler added to the server context
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 781
diff changeset
135 LOG(WARNING) << "The server scheduler has started";
c9cdd53a6b31 main scheduler added to the server context
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 781
diff changeset
136
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 while (!that->finish_)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 std::auto_ptr<IDynamicObject> object(that->queue_.Dequeue(TIMEOUT));
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 if (object.get() != NULL)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
142 ServerCommandInstance& filter = dynamic_cast<ServerCommandInstance&>(*object);
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 // Skip the execution of this filter if its parent job has
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 // previously failed.
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 bool jobHasFailed;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 boost::mutex::scoped_lock lock(that->mutex_);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 JobInfo& info = that->GetJobInfo(filter.GetJobId());
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 jobHasFailed = (info.failures_ > 0 || info.cancel_);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 if (jobHasFailed)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 that->SignalFailure(filter.GetJobId());
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 else
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 filter.Execute(*that);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 void ServerScheduler::SubmitInternal(ServerJob& job,
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 bool watched)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
995
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 783
diff changeset
169 availableJob_.Acquire();
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 783
diff changeset
170
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 boost::mutex::scoped_lock lock(mutex_);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 JobInfo info;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 info.size_ = job.Submit(queue_, *this);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 info.cancel_ = false;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 info.success_ = 0;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 info.failures_ = 0;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 info.description_ = job.GetDescription();
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 info.watched_ = watched;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 assert(info.size_ > 0);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 if (watched)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 watchedJobStatus_[job.GetId()] = JobStatus_Running;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 jobs_[job.GetId()] = info;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 LOG(INFO) << "New job submitted (" << job.description_ << ")";
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
995
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 783
diff changeset
194 ServerScheduler::ServerScheduler(unsigned int maxJobs) : availableJob_(maxJobs)
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
2063
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
196 if (maxJobs == 0)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
197 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
198 throw OrthancException(ErrorCode_ParameterOutOfRange);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
199 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
200
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 finish_ = false;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 worker_ = boost::thread(Worker, this);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 ServerScheduler::~ServerScheduler()
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 {
1453
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
208 if (!finish_)
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
209 {
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
210 LOG(ERROR) << "INTERNAL ERROR: ServerScheduler::Finalize() should be invoked manually to avoid mess in the destruction order!";
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
211 Stop();
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
212 }
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
213 }
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
214
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
215
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
216 void ServerScheduler::Stop()
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
217 {
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
218 if (!finish_)
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
219 {
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
220 finish_ = true;
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
221
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
222 if (worker_.joinable())
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
223 {
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
224 worker_.join();
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
225 }
c0bdc47165ef code to warn about possible threading problems
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
226 }
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 void ServerScheduler::Submit(ServerJob& job)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 if (job.filters_.empty())
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 return;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 SubmitInternal(job, false);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 bool ServerScheduler::SubmitAndWait(ListOfStrings& outputs,
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 ServerJob& job)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 std::string jobId = job.GetId();
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 outputs.clear();
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 if (job.filters_.empty())
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 return true;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 // Add a sink filter to collect all the results of the filters
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 // that have no next filter.
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
255 ServerCommandInstance& sink = job.AddCommand(new Sink(outputs));
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
1000
13e230bbd882 rename filter to command
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 999
diff changeset
257 for (std::list<ServerCommandInstance*>::iterator
1304
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
258 it = job.filters_.begin(); it != job.filters_.end(); ++it)
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 if ((*it) != &sink &&
1009
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1000
diff changeset
261 (*it)->IsConnectedToSink())
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 {
1009
26642cecd36d clearer job interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1000
diff changeset
263 (*it)->ConnectOutput(sink);
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 // Submit the job
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 SubmitInternal(job, true);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 // Wait for the job to complete (either success or failure)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 JobStatus status;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 boost::mutex::scoped_lock lock(mutex_);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 assert(watchedJobStatus_.find(jobId) != watchedJobStatus_.end());
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 while (watchedJobStatus_[jobId] == JobStatus_Running)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 {
995
8c67382f44a7 limit number of jobs in the scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 783
diff changeset
280 watchedJobFinished_.wait(lock);
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 status = watchedJobStatus_[jobId];
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 watchedJobStatus_.erase(jobId);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 return (status == JobStatus_Success);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
999
db18c071fbd7 store-scu filter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
291 bool ServerScheduler::SubmitAndWait(ServerJob& job)
db18c071fbd7 store-scu filter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
292 {
db18c071fbd7 store-scu filter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
293 ListOfStrings ignoredSink;
db18c071fbd7 store-scu filter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
294 return SubmitAndWait(ignoredSink, job);
db18c071fbd7 store-scu filter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
295 }
db18c071fbd7 store-scu filter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
296
db18c071fbd7 store-scu filter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 995
diff changeset
297
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 bool ServerScheduler::IsRunning(const std::string& jobId)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 boost::mutex::scoped_lock lock(mutex_);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 return jobs_.find(jobId) != jobs_.end();
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 void ServerScheduler::Cancel(const std::string& jobId)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 boost::mutex::scoped_lock lock(mutex_);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 Jobs::iterator job = jobs_.find(jobId);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 if (job != jobs_.end())
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 job->second.cancel_ = true;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 LOG(WARNING) << "Canceling a job (" << job->second.description_ << ")";
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 float ServerScheduler::GetProgress(const std::string& jobId)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 boost::mutex::scoped_lock lock(mutex_);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 Jobs::iterator job = jobs_.find(jobId);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 if (job == jobs_.end() ||
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 job->second.size_ == 0 /* should never happen */)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 // This job is not running
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 return 1;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 if (job->second.failures_ != 0)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 return 1;
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 if (job->second.size_ == 1)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 {
1545
33d34bc4ac15 fix msvc warnings
jodogne
parents: 1486
diff changeset
339 return static_cast<float>(job->second.success_);
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 return (static_cast<float>(job->second.success_) /
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 static_cast<float>(job->second.size_ - 1));
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 void ServerScheduler::GetListOfJobs(ListOfStrings& jobs)
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 boost::mutex::scoped_lock lock(mutex_);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 jobs.clear();
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 for (Jobs::const_iterator
1304
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
354 it = jobs_.begin(); it != jobs_.end(); ++it)
781
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 {
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 jobs.push_back(it->first);
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 }
f0ac3a53ccf2 scheduler
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 }