annotate OrthancFramework/Sources/JobsEngine/JobsEngine.h @ 4767:e1711b6e141f

Fix computation of the estimated time of arrival in jobs
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 18 Aug 2021 15:16:39 +0200
parents d9473bd5ed43
children 7053502fbf97
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
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4202
diff changeset
5 * Copyright (C) 2017-2021 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
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
10 * the License, or (at your option) any later version.
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
15 * Lesser General Public License for more details.
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
19 * <http://www.gnu.org/licenses/>.
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #pragma once
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "JobsRegistry.h"
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
27 #include "../Compatibility.h"
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
28
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <boost/thread.hpp>
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 namespace Orthanc
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 {
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
33 class ORTHANC_PUBLIC JobsEngine : public boost::noncopyable
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 private:
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 enum State
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 State_Setup,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 State_Running,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 State_Stopping,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 State_Done
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 };
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
2591
441f23af9d89 fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
44 boost::mutex stateMutex_;
441f23af9d89 fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
45 State state_;
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
46 std::unique_ptr<JobsRegistry> registry_;
2591
441f23af9d89 fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
47 boost::thread retryHandler_;
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
48 unsigned int threadSleep_;
2591
441f23af9d89 fix for older releases of boost::thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
49 std::vector<boost::thread*> workers_;
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
2573
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
51 bool IsRunning();
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
52
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 bool ExecuteStep(JobsRegistry::RunningJob& running,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 size_t workerIndex);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 static void RetryHandler(JobsEngine* engine);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 static void Worker(JobsEngine* engine,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 size_t workerIndex);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 public:
4202
2007ab69ac16 moving ORTHANC_FORCE_INLINE and ORTHANC_OVERRIDE from Enumerations.h to Compatibility.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
62 explicit JobsEngine(size_t maxCompletedJobs);
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 ~JobsEngine();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
2668
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
66 JobsRegistry& GetRegistry();
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
67
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
68 void LoadRegistryFromJson(IJobUnserializer& unserializer,
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
69 const Json::Value& serialized);
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
70
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
71 void LoadRegistryFromString(IJobUnserializer& unserializer,
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
72 const std::string& serialized);
d26dd081df97 saving jobs engine on exit
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2665
diff changeset
73
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 void SetWorkersCount(size_t count);
2665
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
75
389d050a2e66 fix deadlock, speed up unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2591
diff changeset
76 void SetThreadSleep(unsigned int sleep);
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 void Start();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 void Stop();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 };
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }