comparison Core/JobsEngine/JobsEngine.cpp @ 2573:3372c5255333 jobs

StoreScuJob, Orthanc Explorer for jobs
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 09 May 2018 17:56:14 +0200
parents 2e879c796ec7
children 8da2cffc2378
comparison
equal deleted inserted replaced
2570:2e879c796ec7 2573:3372c5255333
39 #include "../Logging.h" 39 #include "../Logging.h"
40 #include "../OrthancException.h" 40 #include "../OrthancException.h"
41 41
42 namespace Orthanc 42 namespace Orthanc
43 { 43 {
44 bool JobsEngine::IsRunning()
45 {
46 boost::mutex::scoped_lock lock(stateMutex_);
47 return (state_ == State_Running);
48 }
49
50
44 bool JobsEngine::ExecuteStep(JobsRegistry::RunningJob& running, 51 bool JobsEngine::ExecuteStep(JobsRegistry::RunningJob& running,
45 size_t workerIndex) 52 size_t workerIndex)
46 { 53 {
47 assert(running.IsValid()); 54 assert(running.IsValid());
48
49 LOG(INFO) << "Executing job with priority " << running.GetPriority()
50 << " in worker thread " << workerIndex << ": " << running.GetId();
51 55
52 if (running.IsPauseScheduled()) 56 if (running.IsPauseScheduled())
53 { 57 {
54 running.GetJob().ReleaseResources(); 58 running.GetJob().ReleaseResources();
55 running.MarkPause(); 59 running.MarkPause();
92 } 96 }
93 97
94 switch (result->GetCode()) 98 switch (result->GetCode())
95 { 99 {
96 case JobStepCode_Success: 100 case JobStepCode_Success:
101 running.GetJob().ReleaseResources();
97 running.MarkSuccess(); 102 running.MarkSuccess();
98 return false; 103 return false;
99 104
100 case JobStepCode_Failure: 105 case JobStepCode_Failure:
106 running.GetJob().ReleaseResources();
101 running.MarkFailure(); 107 running.MarkFailure();
102 return false; 108 return false;
103 109
104 case JobStepCode_Retry: 110 case JobStepCode_Retry:
105 running.GetJob().ReleaseResources(); 111 running.GetJob().ReleaseResources();
117 123
118 void JobsEngine::RetryHandler(JobsEngine* engine) 124 void JobsEngine::RetryHandler(JobsEngine* engine)
119 { 125 {
120 assert(engine != NULL); 126 assert(engine != NULL);
121 127
122 for (;;) 128 while (engine->IsRunning())
123 { 129 {
124 boost::this_thread::sleep(boost::posix_time::milliseconds(200)); 130 boost::this_thread::sleep(boost::posix_time::milliseconds(200));
125
126 {
127 boost::mutex::scoped_lock lock(engine->stateMutex_);
128
129 if (engine->state_ != State_Running)
130 {
131 return;
132 }
133 }
134
135 engine->GetRegistry().ScheduleRetries(); 131 engine->GetRegistry().ScheduleRetries();
136 } 132 }
137 } 133 }
138 134
139 135
142 { 138 {
143 assert(engine != NULL); 139 assert(engine != NULL);
144 140
145 LOG(INFO) << "Worker thread " << workerIndex << " has started"; 141 LOG(INFO) << "Worker thread " << workerIndex << " has started";
146 142
147 for (;;) 143 while (engine->IsRunning())
148 { 144 {
149 {
150 boost::mutex::scoped_lock lock(engine->stateMutex_);
151
152 if (engine->state_ != State_Running)
153 {
154 return;
155 }
156 }
157
158 JobsRegistry::RunningJob running(engine->GetRegistry(), 100); 145 JobsRegistry::RunningJob running(engine->GetRegistry(), 100);
159 146
160 if (running.IsValid()) 147 if (running.IsValid())
161 { 148 {
162 for (;;) 149 LOG(INFO) << "Executing job with priority " << running.GetPriority()
150 << " in worker thread " << workerIndex << ": " << running.GetId();
151
152 while (engine->IsRunning())
163 { 153 {
164 if (!engine->ExecuteStep(running, workerIndex)) 154 if (!engine->ExecuteStep(running, workerIndex))
165 { 155 {
166 break; 156 break;
167 } 157 }