annotate Core/JobsEngine/JobsRegistry.h @ 2658:ce770f095092 jobs

todo
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 06 Jun 2018 18:37:43 +0200
parents e1893d31652a
children 5fa2f2ce74f0
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
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
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 #pragma once
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #if !defined(ORTHANC_SANDBOXED)
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 # error The macro ORTHANC_SANDBOXED must be defined
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #endif
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #if ORTHANC_SANDBOXED == 1
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 # error The job engine cannot be used in sandboxed environments
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 #endif
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 #include "JobInfo.h"
2648
e1893d31652a serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
45 #include "IJobUnserializer.h"
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 #include <list>
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 #include <set>
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 #include <queue>
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 #include <boost/thread/mutex.hpp>
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 #include <boost/thread/condition_variable.hpp>
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 namespace Orthanc
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 // This class handles the state machine of the jobs engine
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 class JobsRegistry : public boost::noncopyable
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 private:
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 class JobHandler;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 struct PriorityComparator
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 bool operator() (JobHandler*& a,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 JobHandler*& b) const;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 };
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 typedef std::map<std::string, JobHandler*> JobsIndex;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 typedef std::list<JobHandler*> CompletedJobs;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 typedef std::set<JobHandler*> RetryJobs;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 typedef std::priority_queue<JobHandler*,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 std::vector<JobHandler*>, // Could be a "std::deque"
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 PriorityComparator> PendingJobs;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 boost::mutex mutex_;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 JobsIndex jobsIndex_;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 PendingJobs pendingJobs_;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 CompletedJobs completedJobs_;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 RetryJobs retryJobs_;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 boost::condition_variable pendingJobAvailable_;
2570
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
81 boost::condition_variable someJobComplete_;
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 size_t maxCompletedJobs_;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 #ifndef NDEBUG
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 bool IsPendingJob(const JobHandler& job) const;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 bool IsCompletedJob(JobHandler& job) const;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 bool IsRetryJob(JobHandler& job) const;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 #endif
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 void CheckInvariants() const;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 void ForgetOldCompletedJobs();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
97 void SetCompletedJob(JobHandler& job,
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
98 bool success);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
99
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 void MarkRunningAsCompleted(JobHandler& job,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 bool success);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 void MarkRunningAsRetry(JobHandler& job,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 unsigned int timeout);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 void MarkRunningAsPaused(JobHandler& job);
2570
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
107
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
108 bool GetStateInternal(JobState& state,
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
109 const std::string& id);
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
111 void RemovePendingJob(const std::string& id);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
112
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
113 void RemoveRetryJob(JobHandler* handler);
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
114
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 public:
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 JobsRegistry() :
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 maxCompletedJobs_(10)
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 ~JobsRegistry();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 void SetMaxCompletedJobs(size_t i);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 void ListJobs(std::set<std::string>& target);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 bool GetJobInfo(JobInfo& target,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 const std::string& id);
2648
e1893d31652a serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
130
e1893d31652a serialization of JobHandler
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2581
diff changeset
131 void Serialize(Json::Value& target);
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 void Submit(std::string& id,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 IJob* job, // Takes ownership
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 int priority);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 void Submit(IJob* job, // Takes ownership
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 int priority);
2570
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
139
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
140 bool SubmitAndWait(IJob* job, // Takes ownership
2e879c796ec7 JobsRegistry::SubmitAndWait(), StoreScuJob
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2569
diff changeset
141 int priority);
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
2573
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
143 bool SetPriority(const std::string& id,
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 int priority);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
2573
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
146 bool Pause(const std::string& id);
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
2573
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
148 bool Resume(const std::string& id);
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149
2573
3372c5255333 StoreScuJob, Orthanc Explorer for jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2570
diff changeset
150 bool Resubmit(const std::string& id);
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
151
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
152 bool Cancel(const std::string& id);
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 void ScheduleRetries();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 bool GetState(JobState& state,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 const std::string& id);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 class RunningJob : public boost::noncopyable
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 {
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 private:
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 JobsRegistry& registry_;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 JobHandler* handler_; // Can only be accessed if the
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 // registry mutex is locked!
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 IJob* job_; // Will by design be in mutual exclusion,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 // because only one RunningJob can be
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 // executed at a time on a JobHandler
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 std::string id_;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 int priority_;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 JobState targetState_;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 unsigned int targetRetryTimeout_;
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
173 bool canceled_;
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 public:
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 RunningJob(JobsRegistry& registry,
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 unsigned int timeout);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 ~RunningJob();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 bool IsValid() const;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 const std::string& GetId() const;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 int GetPriority() const;
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 IJob& GetJob();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 bool IsPauseScheduled();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
191 bool IsCancelScheduled();
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
192
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 void MarkSuccess();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 void MarkFailure();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 void MarkPause();
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
2581
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
199 void MarkCanceled();
8da2cffc2378 JobsRegistry::Cancel()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2573
diff changeset
200
2569
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 void MarkRetry(unsigned int timeout);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 void UpdateStatus(ErrorCode code);
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 };
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 };
2af17cd5eb1f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 }