annotate Core/JobsEngine/JobsEngine.cpp @ 3867:7a7d18875985 c-get

integration mainline->c-get
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 27 Apr 2020 18:36:19 +0200
parents 2d90dd30858c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3240
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
2af17cd5eb1f reorganization
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
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "../PrecompiledHeaders.h"
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "JobsEngine.h"
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include "../Logging.h"
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "../OrthancException.h"
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
40 #include <json/reader.h>
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
41
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 namespace Orthanc
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
2573
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
44 bool JobsEngine::IsRunning()
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
45 {
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
46 boost::mutex::scoped_lock lock(stateMutex_);
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
47 return (state_ == State_Running);
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
48 }
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
49
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
50
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 bool JobsEngine::ExecuteStep(JobsRegistry::RunningJob& running,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 size_t workerIndex)
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 assert(running.IsValid());
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 if (running.IsPauseScheduled())
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
58 running.GetJob().Stop(JobStopReason_Paused);
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 running.MarkPause();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 return false;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
63 if (running.IsCancelScheduled())
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
64 {
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
65 running.GetJob().Stop(JobStopReason_Canceled);
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
66 running.MarkCanceled();
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
67 return false;
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
68 }
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
69
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
70 JobStepResult result;
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
72 try
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
73 {
3658
2d90dd30858c providing job ID to the IJob::Step() methods
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
74 result = running.GetJob().Step(running.GetId());
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
75 }
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
76 catch (OrthancException& e)
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
77 {
3240
e44e0127e553 Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
78 result = JobStepResult::Failure(e);
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
79 }
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
80 catch (boost::bad_lexical_cast&)
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
81 {
3240
e44e0127e553 Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
82 result = JobStepResult::Failure(ErrorCode_BadFileFormat, NULL);
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
83 }
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
84 catch (...)
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
85 {
3240
e44e0127e553 Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
86 result = JobStepResult::Failure(ErrorCode_InternalError, NULL);
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
89 switch (result.GetCode())
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 case JobStepCode_Success:
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
92 running.GetJob().Stop(JobStopReason_Success);
3240
e44e0127e553 Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
93 running.UpdateStatus(ErrorCode_Success, "");
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 running.MarkSuccess();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 return false;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 case JobStepCode_Failure:
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
98 running.GetJob().Stop(JobStopReason_Failure);
3240
e44e0127e553 Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
99 running.UpdateStatus(result.GetFailureCode(), result.GetFailureDetails());
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 running.MarkFailure();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 return false;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 case JobStepCode_Retry:
2812
ea7aea6f6a95 improved naming of methods in IJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2811
diff changeset
104 running.GetJob().Stop(JobStopReason_Retry);
3240
e44e0127e553 Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
105 running.UpdateStatus(ErrorCode_Success, "");
2598
34dc57f4a7d2 simplification of JobStepResult
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
106 running.MarkRetry(result.GetRetryTimeout());
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 return false;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 case JobStepCode_Continue:
3240
e44e0127e553 Fix issue #134 (/patient/modify gives 500, should really be 400)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
110 running.UpdateStatus(ErrorCode_Success, "");
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 return true;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 default:
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 throw OrthancException(ErrorCode_InternalError);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 void JobsEngine::RetryHandler(JobsEngine* engine)
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 assert(engine != NULL);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
2573
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
123 while (engine->IsRunning())
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
125 boost::this_thread::sleep(boost::posix_time::milliseconds(engine->threadSleep_));
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 engine->GetRegistry().ScheduleRetries();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 void JobsEngine::Worker(JobsEngine* engine,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 size_t workerIndex)
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 assert(engine != NULL);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 LOG(INFO) << "Worker thread " << workerIndex << " has started";
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
2573
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
138 while (engine->IsRunning())
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
140 JobsRegistry::RunningJob running(engine->GetRegistry(), engine->threadSleep_);
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 if (running.IsValid())
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
2573
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
144 LOG(INFO) << "Executing job with priority " << running.GetPriority()
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
145 << " in worker thread " << workerIndex << ": " << running.GetId();
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
146
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
147 while (engine->IsRunning())
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 if (!engine->ExecuteStep(running, workerIndex))
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 break;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
159 JobsEngine::JobsEngine(size_t maxCompletedJobs) :
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 state_(State_Setup),
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
161 registry_(new JobsRegistry(maxCompletedJobs)),
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
162 threadSleep_(200),
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 workers_(1)
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 JobsEngine::~JobsEngine()
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 if (state_ != State_Setup &&
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 state_ != State_Done)
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 LOG(ERROR) << "INTERNAL ERROR: JobsEngine::Stop() should be invoked manually to avoid mess in the destruction order!";
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 Stop();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
178
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
179 JobsRegistry& JobsEngine::GetRegistry()
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
180 {
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
181 if (registry_.get() == NULL)
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
182 {
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
183 throw OrthancException(ErrorCode_InternalError);
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
184 }
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
185
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
186 return *registry_;
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
187 }
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
188
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
189
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
190 void JobsEngine::LoadRegistryFromJson(IJobUnserializer& unserializer,
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
191 const Json::Value& serialized)
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
192 {
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
193 boost::mutex::scoped_lock lock(stateMutex_);
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
194
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
195 if (state_ != State_Setup)
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
196 {
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
197 // Can only be invoked before calling "Start()"
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
198 throw OrthancException(ErrorCode_BadSequenceOfCalls);
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
199 }
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
200
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
201 assert(registry_.get() != NULL);
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
202 const size_t maxCompletedJobs = registry_->GetMaxCompletedJobs();
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2812
diff changeset
203 registry_.reset(new JobsRegistry(unserializer, serialized, maxCompletedJobs));
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
204 }
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
205
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
206
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
207 void JobsEngine::LoadRegistryFromString(IJobUnserializer& unserializer,
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
208 const std::string& serialized)
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
209 {
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
210 Json::Value value;
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
211 Json::Reader reader;
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
212 if (reader.parse(serialized, value))
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
213 {
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
214 LoadRegistryFromJson(unserializer, value);
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
215 }
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
216 else
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
217 {
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
218 throw OrthancException(ErrorCode_BadFileFormat);
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
219 }
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
220 }
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
221
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
222
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 void JobsEngine::SetWorkersCount(size_t count)
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 boost::mutex::scoped_lock lock(stateMutex_);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 if (state_ != State_Setup)
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 // Can only be invoked before calling "Start()"
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 throw OrthancException(ErrorCode_BadSequenceOfCalls);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 workers_.resize(count);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 }
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
235
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
236
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
237 void JobsEngine::SetThreadSleep(unsigned int sleep)
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
238 {
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
239 boost::mutex::scoped_lock lock(stateMutex_);
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
240
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
241 if (state_ != State_Setup)
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
242 {
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
243 // Can only be invoked before calling "Start()"
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
244 throw OrthancException(ErrorCode_BadSequenceOfCalls);
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
245 }
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
246
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
247 threadSleep_ = sleep;
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
248 }
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2598
diff changeset
249
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 void JobsEngine::Start()
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 boost::mutex::scoped_lock lock(stateMutex_);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 if (state_ != State_Setup)
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 throw OrthancException(ErrorCode_BadSequenceOfCalls);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 retryHandler_ = boost::thread(RetryHandler, this);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
2570
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
262 if (workers_.size() == 0)
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
263 {
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
264 // Use all the available CPUs
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
265 size_t n = boost::thread::hardware_concurrency();
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
266
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
267 if (n == 0)
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
268 {
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
269 n = 1;
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
270 }
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
271
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
272 workers_.resize(n);
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
273 }
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
274
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 for (size_t i = 0; i < workers_.size(); i++)
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 {
2591
441f23af9d89 fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
277 assert(workers_[i] == NULL);
441f23af9d89 fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
278 workers_[i] = new boost::thread(Worker, this, i);
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 state_ = State_Running;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282
2570
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
283 LOG(WARNING) << "The jobs engine has started with " << workers_.size() << " threads";
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 void JobsEngine::Stop()
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 boost::mutex::scoped_lock lock(stateMutex_);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 if (state_ != State_Running)
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 return;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 state_ = State_Stopping;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 LOG(INFO) << "Stopping the jobs engine";
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 if (retryHandler_.joinable())
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 retryHandler_.join();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 for (size_t i = 0; i < workers_.size(); i++)
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 {
2591
441f23af9d89 fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
309 assert(workers_[i] != NULL);
441f23af9d89 fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
310
441f23af9d89 fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
311 if (workers_[i]->joinable())
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 {
2591
441f23af9d89 fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
313 workers_[i]->join();
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 }
2591
441f23af9d89 fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
315
441f23af9d89 fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
316 delete workers_[i];
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 boost::mutex::scoped_lock lock(stateMutex_);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 state_ = State_Done;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 LOG(WARNING) << "The jobs engine has stopped";
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 }