Mercurial > hg > orthanc
annotate OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp @ 5185:0ea402b4d901
upgrade to year 2023
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 25 Mar 2023 12:27:21 +0100 |
parents | 67d98fccc850 |
children | a47b24f231d0 |
rev | line source |
---|---|
4961 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5035
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5035
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
4961 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #include "../../../../OrthancFramework/Sources/Compatibility.h" | |
24 #include "../Common/OrthancPluginCppWrapper.h" | |
25 | |
26 #include <boost/thread.hpp> | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
27 #include <boost/algorithm/string.hpp> |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
28 #include <boost/date_time/posix_time/posix_time.hpp> |
4991 | 29 #include <boost/date_time/special_defs.hpp> |
4961 | 30 #include <json/value.h> |
31 #include <json/writer.h> | |
32 #include <string.h> | |
33 #include <iostream> | |
34 #include <algorithm> | |
35 #include <map> | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
36 #include <list> |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
37 #include <time.h> |
4961 | 38 |
39 static int globalPropertyId_ = 0; | |
40 static bool force_ = false; | |
4982
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
41 static unsigned int throttleDelay_ = 0; |
4961 | 42 static std::unique_ptr<boost::thread> workerThread_; |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
43 static bool workerThreadShouldStop_ = false; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
44 static bool triggerOnStorageCompressionChange_ = true; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
45 static bool triggerOnMainDicomTagsChange_ = true; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
46 static bool triggerOnUnnecessaryDicomAsJsonFiles_ = true; |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
47 static bool triggerOnIngestTranscodingChange_ = true; |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
48 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
49 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
50 struct RunningPeriod |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
51 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
52 int fromHour_; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
53 int toHour_; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
54 int weekday_; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
55 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
56 RunningPeriod(const std::string& weekday, const std::string& period) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
57 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
58 if (weekday == "Monday") |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
59 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
60 weekday_ = 1; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
61 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
62 else if (weekday == "Tuesday") |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
63 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
64 weekday_ = 2; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
65 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
66 else if (weekday == "Wednesday") |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
67 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
68 weekday_ = 3; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
69 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
70 else if (weekday == "Thursday") |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
71 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
72 weekday_ = 4; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
73 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
74 else if (weekday == "Friday") |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
75 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
76 weekday_ = 5; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
77 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
78 else if (weekday == "Saturday") |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
79 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
80 weekday_ = 6; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
81 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
82 else if (weekday == "Sunday") |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
83 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
84 weekday_ = 0; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
85 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
86 else |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
87 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
88 OrthancPlugins::LogWarning("Housekeeper: invalid schedule: unknown 'day': " + weekday); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
89 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
90 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
91 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
92 std::vector<std::string> hours; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
93 boost::split(hours, period, boost::is_any_of("-")); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
94 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
95 fromHour_ = boost::lexical_cast<int>(hours[0]); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
96 toHour_ = boost::lexical_cast<int>(hours[1]); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
97 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
98 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
99 bool isInPeriod() const |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
100 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
101 time_t now = time(NULL); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
102 tm* nowLocalTime = localtime(&now); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
103 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
104 if (nowLocalTime->tm_wday != weekday_) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
105 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
106 return false; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
107 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
108 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
109 if (nowLocalTime->tm_hour >= fromHour_ && nowLocalTime->tm_hour < toHour_) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
110 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
111 return true; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
112 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
113 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
114 return false; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
115 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
116 }; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
117 |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
118 |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
119 struct RunningPeriods |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
120 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
121 std::list<RunningPeriod> runningPeriods_; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
122 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
123 void load(const Json::Value& scheduleConfiguration) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
124 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
125 // "Monday": ["0-6", "20-24"], |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
126 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
127 Json::Value::Members names = scheduleConfiguration.getMemberNames(); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
128 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
129 for (Json::Value::Members::const_iterator it = names.begin(); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
130 it != names.end(); it++) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
131 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
132 for (Json::Value::ArrayIndex i = 0; i < scheduleConfiguration[*it].size(); i++) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
133 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
134 runningPeriods_.push_back(RunningPeriod(*it, scheduleConfiguration[*it][i].asString())); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
135 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
136 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
137 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
138 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
139 bool isInPeriod() |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
140 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
141 if (runningPeriods_.size() == 0) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
142 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
143 return true; // if no config: always run |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
144 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
145 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
146 for (std::list<RunningPeriod>::const_iterator it = runningPeriods_.begin(); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
147 it != runningPeriods_.end(); it++) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
148 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
149 if (it->isInPeriod()) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
150 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
151 return true; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
152 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
153 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
154 return false; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
155 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
156 }; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
157 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
158 RunningPeriods runningPeriods_; |
4961 | 159 |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
160 |
4961 | 161 struct DbConfiguration |
162 { | |
163 std::string orthancVersion; | |
4982
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
164 std::string patientsMainDicomTagsSignature; |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
165 std::string studiesMainDicomTagsSignature; |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
166 std::string seriesMainDicomTagsSignature; |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
167 std::string instancesMainDicomTagsSignature; |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
168 std::string ingestTranscoding; |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
169 bool storageCompressionEnabled; |
4961 | 170 |
171 DbConfiguration() | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
172 : storageCompressionEnabled(false) |
4961 | 173 { |
174 } | |
175 | |
176 bool IsDefined() const | |
177 { | |
4982
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
178 return !orthancVersion.empty(); |
4961 | 179 } |
180 | |
181 void Clear() | |
182 { | |
183 orthancVersion.clear(); | |
4982
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
184 patientsMainDicomTagsSignature.clear(); |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
185 studiesMainDicomTagsSignature.clear(); |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
186 seriesMainDicomTagsSignature.clear(); |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
187 instancesMainDicomTagsSignature.clear(); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
188 ingestTranscoding.clear(); |
4961 | 189 } |
190 | |
191 void ToJson(Json::Value& target) | |
192 { | |
193 if (!IsDefined()) | |
194 { | |
195 target = Json::nullValue; | |
196 } | |
197 else | |
198 { | |
199 Json::Value signatures; | |
200 | |
201 target = Json::objectValue; | |
202 | |
203 // default main dicom tags signature are the one from Orthanc 1.4.2 (last time the list was changed): | |
4982
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
204 signatures["Patient"] = patientsMainDicomTagsSignature; |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
205 signatures["Study"] = studiesMainDicomTagsSignature; |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
206 signatures["Series"] = seriesMainDicomTagsSignature; |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
207 signatures["Instance"] = instancesMainDicomTagsSignature; |
4961 | 208 |
209 target["MainDicomTagsSignature"] = signatures; | |
210 target["OrthancVersion"] = orthancVersion; | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
211 target["StorageCompressionEnabled"] = storageCompressionEnabled; |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
212 target["IngestTranscoding"] = ingestTranscoding; |
4961 | 213 } |
214 } | |
215 | |
216 void FromJson(Json::Value& source) | |
217 { | |
218 if (!source.isNull()) | |
219 { | |
220 orthancVersion = source["OrthancVersion"].asString(); | |
221 | |
222 const Json::Value& signatures = source["MainDicomTagsSignature"]; | |
4982
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
223 patientsMainDicomTagsSignature = signatures["Patient"].asString(); |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
224 studiesMainDicomTagsSignature = signatures["Study"].asString(); |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
225 seriesMainDicomTagsSignature = signatures["Series"].asString(); |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
226 instancesMainDicomTagsSignature = signatures["Instance"].asString(); |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
227 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
228 storageCompressionEnabled = source["StorageCompressionEnabled"].asBool(); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
229 ingestTranscoding = source["IngestTranscoding"].asString(); |
4961 | 230 } |
231 } | |
232 }; | |
233 | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
234 |
4961 | 235 struct PluginStatus |
236 { | |
237 int statusVersion; | |
238 int64_t lastProcessedChange; | |
239 int64_t lastChangeToProcess; | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
240 boost::posix_time::ptime lastTimeStarted; |
4961 | 241 |
242 DbConfiguration currentlyProcessingConfiguration; // last configuration being processed (has not reached last change yet) | |
243 DbConfiguration lastProcessedConfiguration; // last configuration that has been fully processed (till last change) | |
244 | |
245 PluginStatus() | |
246 : statusVersion(1), | |
247 lastProcessedChange(-1), | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
248 lastChangeToProcess(-1), |
4993 | 249 lastTimeStarted(boost::date_time::not_a_date_time) |
4961 | 250 { |
251 } | |
252 | |
253 void ToJson(Json::Value& target) | |
254 { | |
255 target = Json::objectValue; | |
256 | |
257 target["Version"] = statusVersion; | |
258 target["LastProcessedChange"] = Json::Value::Int64(lastProcessedChange); | |
259 target["LastChangeToProcess"] = Json::Value::Int64(lastChangeToProcess); | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
260 |
4993 | 261 if (lastTimeStarted == boost::date_time::not_a_date_time) |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
262 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
263 target["LastTimeStarted"] = Json::Value::null; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
264 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
265 else |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
266 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
267 target["LastTimeStarted"] = boost::posix_time::to_iso_string(lastTimeStarted); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
268 } |
4961 | 269 |
270 currentlyProcessingConfiguration.ToJson(target["CurrentlyProcessingConfiguration"]); | |
271 lastProcessedConfiguration.ToJson(target["LastProcessedConfiguration"]); | |
272 } | |
273 | |
274 void FromJson(Json::Value& source) | |
275 { | |
276 statusVersion = source["Version"].asInt(); | |
277 lastProcessedChange = source["LastProcessedChange"].asInt64(); | |
278 lastChangeToProcess = source["LastChangeToProcess"].asInt64(); | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
279 if (source["LastTimeStarted"].isNull()) |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
280 { |
4993 | 281 lastTimeStarted = boost::date_time::not_a_date_time; |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
282 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
283 else |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
284 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
285 lastTimeStarted = boost::posix_time::from_iso_string(source["LastTimeStarted"].asString()); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
286 } |
4961 | 287 |
288 Json::Value& current = source["CurrentlyProcessingConfiguration"]; | |
289 Json::Value& last = source["LastProcessedConfiguration"]; | |
290 | |
291 currentlyProcessingConfiguration.FromJson(current); | |
292 lastProcessedConfiguration.FromJson(last); | |
293 } | |
294 }; | |
295 | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
296 static PluginStatus pluginStatus_; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
297 static boost::recursive_mutex pluginStatusMutex_; |
4961 | 298 |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
299 static void ReadStatusFromDb() |
4961 | 300 { |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
301 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
302 |
4961 | 303 OrthancPlugins::OrthancString globalPropertyContent; |
304 | |
305 globalPropertyContent.Assign(OrthancPluginGetGlobalProperty(OrthancPlugins::GetGlobalContext(), | |
306 globalPropertyId_, | |
307 "")); | |
308 | |
309 if (!globalPropertyContent.IsNullOrEmpty()) | |
310 { | |
311 Json::Value jsonStatus; | |
312 globalPropertyContent.ToJson(jsonStatus); | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
313 pluginStatus_.FromJson(jsonStatus); |
4961 | 314 } |
315 else | |
316 { | |
317 // default config | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
318 pluginStatus_.statusVersion = 1; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
319 pluginStatus_.lastProcessedChange = -1; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
320 pluginStatus_.lastChangeToProcess = -1; |
4993 | 321 pluginStatus_.lastTimeStarted = boost::date_time::not_a_date_time; |
4961 | 322 |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
323 pluginStatus_.lastProcessedConfiguration.orthancVersion = "1.9.0"; // when we don't know, we assume some files were stored with Orthanc 1.9.0 (last version saving the dicom-as-json files) |
4961 | 324 |
325 // default main dicom tags signature are the one from Orthanc 1.4.2 (last time the list was changed): | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
326 pluginStatus_.lastProcessedConfiguration.patientsMainDicomTagsSignature = "0010,0010;0010,0020;0010,0030;0010,0040;0010,1000"; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
327 pluginStatus_.lastProcessedConfiguration.studiesMainDicomTagsSignature = "0008,0020;0008,0030;0008,0050;0008,0080;0008,0090;0008,1030;0020,000d;0020,0010;0032,1032;0032,1060"; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
328 pluginStatus_.lastProcessedConfiguration.seriesMainDicomTagsSignature = "0008,0021;0008,0031;0008,0060;0008,0070;0008,1010;0008,103e;0008,1070;0018,0010;0018,0015;0018,0024;0018,1030;0018,1090;0018,1400;0020,000e;0020,0011;0020,0037;0020,0105;0020,1002;0040,0254;0054,0081;0054,0101;0054,1000"; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
329 pluginStatus_.lastProcessedConfiguration.instancesMainDicomTagsSignature = "0008,0012;0008,0013;0008,0018;0020,0012;0020,0013;0020,0032;0020,0037;0020,0100;0020,4000;0028,0008;0054,1330"; |
4961 | 330 } |
331 } | |
332 | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
333 static void SaveStatusInDb() |
4961 | 334 { |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
335 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
336 |
4961 | 337 Json::Value jsonStatus; |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
338 pluginStatus_.ToJson(jsonStatus); |
4961 | 339 |
340 Json::StreamWriterBuilder builder; | |
341 builder.settings_["indentation"] = " "; | |
342 std::string serializedStatus = Json::writeString(builder, jsonStatus); | |
343 | |
344 OrthancPluginSetGlobalProperty(OrthancPlugins::GetGlobalContext(), | |
345 globalPropertyId_, | |
346 serializedStatus.c_str()); | |
347 } | |
348 | |
349 static void GetCurrentDbConfiguration(DbConfiguration& configuration) | |
350 { | |
351 Json::Value signatures; | |
352 Json::Value systemInfo; | |
353 | |
354 OrthancPlugins::RestApiGet(systemInfo, "/system", false); | |
4982
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
355 configuration.patientsMainDicomTagsSignature = systemInfo["MainDicomTags"]["Patient"].asString(); |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
356 configuration.studiesMainDicomTagsSignature = systemInfo["MainDicomTags"]["Study"].asString(); |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
357 configuration.seriesMainDicomTagsSignature = systemInfo["MainDicomTags"]["Series"].asString(); |
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
358 configuration.instancesMainDicomTagsSignature = systemInfo["MainDicomTags"]["Instance"].asString(); |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
359 configuration.storageCompressionEnabled = systemInfo["StorageCompression"].asBool(); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
360 configuration.ingestTranscoding = systemInfo["IngestTranscoding"].asString(); |
4961 | 361 |
362 configuration.orthancVersion = OrthancPlugins::GetGlobalContext()->orthancVersion; | |
363 } | |
364 | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
365 static void CheckNeedsProcessing(bool& needsReconstruct, bool& needsReingest, const DbConfiguration& current, const DbConfiguration& last) |
4961 | 366 { |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
367 needsReconstruct = false; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
368 needsReingest = false; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
369 |
4961 | 370 if (!last.IsDefined()) |
371 { | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
372 return; |
4961 | 373 } |
374 | |
375 const char* lastVersion = last.orthancVersion.c_str(); | |
376 | |
377 if (!OrthancPlugins::CheckMinimalVersion(lastVersion, 1, 9, 1)) | |
378 { | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
379 if (triggerOnUnnecessaryDicomAsJsonFiles_) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
380 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
381 OrthancPlugins::LogWarning("Housekeeper: your storage might still contain some dicom-as-json files -> will perform housekeeping"); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
382 needsReconstruct = true; // the default reconstruct removes the dicom-as-json |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
383 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
384 else |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
385 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
386 OrthancPlugins::LogWarning("Housekeeper: your storage might still contain some dicom-as-json files but the trigger has been disabled"); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
387 } |
4961 | 388 } |
389 | |
4982
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
390 if (last.patientsMainDicomTagsSignature != current.patientsMainDicomTagsSignature) |
4961 | 391 { |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
392 if (triggerOnMainDicomTagsChange_) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
393 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
394 OrthancPlugins::LogWarning("Housekeeper: Patient main dicom tags have changed, -> will perform housekeeping"); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
395 needsReconstruct = true; |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
396 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
397 else |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
398 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
399 OrthancPlugins::LogWarning("Housekeeper: Patient main dicom tags have changed but the trigger is disabled"); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
400 } |
4961 | 401 } |
402 | |
4982
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
403 if (last.studiesMainDicomTagsSignature != current.studiesMainDicomTagsSignature) |
4961 | 404 { |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
405 if (triggerOnMainDicomTagsChange_) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
406 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
407 OrthancPlugins::LogWarning("Housekeeper: Study main dicom tags have changed, -> will perform housekeeping"); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
408 needsReconstruct = true; |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
409 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
410 else |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
411 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
412 OrthancPlugins::LogWarning("Housekeeper: Study main dicom tags have changed but the trigger is disabled"); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
413 } |
4961 | 414 } |
415 | |
4982
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
416 if (last.seriesMainDicomTagsSignature != current.seriesMainDicomTagsSignature) |
4961 | 417 { |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
418 if (triggerOnMainDicomTagsChange_) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
419 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
420 OrthancPlugins::LogWarning("Housekeeper: Series main dicom tags have changed, -> will perform housekeeping"); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
421 needsReconstruct = true; |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
422 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
423 else |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
424 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
425 OrthancPlugins::LogWarning("Housekeeper: Series main dicom tags have changed but the trigger is disabled"); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
426 } |
4961 | 427 } |
428 | |
4982
40fd2a485a84
fix build for older compilers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4981
diff
changeset
|
429 if (last.instancesMainDicomTagsSignature != current.instancesMainDicomTagsSignature) |
4961 | 430 { |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
431 if (triggerOnMainDicomTagsChange_) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
432 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
433 OrthancPlugins::LogWarning("Housekeeper: Instance main dicom tags have changed, -> will perform housekeeping"); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
434 needsReconstruct = true; |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
435 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
436 else |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
437 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
438 OrthancPlugins::LogWarning("Housekeeper: Instance main dicom tags have changed but the trigger is disabled"); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
439 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
440 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
441 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
442 if (current.storageCompressionEnabled != last.storageCompressionEnabled) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
443 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
444 if (triggerOnStorageCompressionChange_) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
445 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
446 if (current.storageCompressionEnabled) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
447 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
448 OrthancPlugins::LogWarning("Housekeeper: storage compression is now enabled -> will perform housekeeping"); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
449 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
450 else |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
451 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
452 OrthancPlugins::LogWarning("Housekeeper: storage compression is now disabled -> will perform housekeeping"); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
453 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
454 |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
455 needsReingest = true; |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
456 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
457 else |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
458 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
459 OrthancPlugins::LogWarning("Housekeeper: storage compression has changed but the trigger is disabled"); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
460 } |
4961 | 461 } |
462 | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
463 if (current.ingestTranscoding != last.ingestTranscoding) |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
464 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
465 if (triggerOnIngestTranscodingChange_) |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
466 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
467 OrthancPlugins::LogWarning("Housekeeper: ingest transcoding has changed -> will perform housekeeping"); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
468 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
469 needsReingest = true; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
470 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
471 else |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
472 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
473 OrthancPlugins::LogWarning("Housekeeper: ingest transcoding has changed but the trigger is disabled"); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
474 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
475 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
476 |
4961 | 477 } |
478 | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
479 static bool ProcessChanges(bool needsReconstruct, bool needsReingest, const DbConfiguration& currentDbConfiguration) |
4961 | 480 { |
481 Json::Value changes; | |
482 | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
483 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
484 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); |
4961 | 485 |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
486 pluginStatus_.currentlyProcessingConfiguration = currentDbConfiguration; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
487 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
488 OrthancPlugins::RestApiGet(changes, "/changes?since=" + boost::lexical_cast<std::string>(pluginStatus_.lastProcessedChange) + "&limit=100", false); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
489 } |
4961 | 490 |
491 for (Json::ArrayIndex i = 0; i < changes["Changes"].size(); i++) | |
492 { | |
493 const Json::Value& change = changes["Changes"][i]; | |
494 int64_t seq = change["Seq"].asInt64(); | |
495 | |
496 if (change["ChangeType"] == "NewStudy") // some StableStudy might be missing if orthanc was shutdown during a StableAge -> consider only the NewStudy events that can not be missed | |
497 { | |
498 Json::Value result; | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
499 Json::Value request; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
500 if (needsReingest) |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
501 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
502 request["ReconstructFiles"] = true; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
503 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
504 OrthancPlugins::RestApiPost(result, "/studies/" + change["ID"].asString() + "/reconstruct", request, false); |
4961 | 505 } |
506 | |
507 { | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
508 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
509 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
510 pluginStatus_.lastProcessedChange = seq; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
511 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
512 if (seq >= pluginStatus_.lastChangeToProcess) // we are done ! |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
513 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
514 return true; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
515 } |
4961 | 516 } |
517 | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
518 if (change["ChangeType"] == "NewStudy") |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
519 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
520 boost::this_thread::sleep(boost::posix_time::milliseconds(throttleDelay_ * 1000)); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
521 } |
4961 | 522 } |
523 | |
524 return false; | |
525 } | |
526 | |
527 | |
528 static void WorkerThread() | |
529 { | |
530 DbConfiguration currentDbConfiguration; | |
531 | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
532 OrthancPluginLogWarning(OrthancPlugins::GetGlobalContext(), "Starting Housekeeper worker thread"); |
4961 | 533 |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
534 ReadStatusFromDb(); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
535 |
4961 | 536 GetCurrentDbConfiguration(currentDbConfiguration); |
537 | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
538 bool needsReconstruct = false; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
539 bool needsReingest = false; |
5009
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
540 bool needsFullProcessing = false; |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
541 bool needsProcessing = false; |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
542 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
543 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
544 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); |
5009
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
545 |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
546 // compare with last full processed configuration |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
547 CheckNeedsProcessing(needsReconstruct, needsReingest, currentDbConfiguration, pluginStatus_.lastProcessedConfiguration); |
5009
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
548 needsFullProcessing = needsReconstruct || needsReingest; |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
549 needsProcessing = needsFullProcessing; |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
550 |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
551 // if a processing was in progress, check if the config has changed since |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
552 if (pluginStatus_.currentlyProcessingConfiguration.IsDefined()) |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
553 { |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
554 needsProcessing = true; // since a processing was in progress, we need at least a partial processing |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
555 |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
556 bool needsReconstruct2 = false; |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
557 bool needsReingest2 = false; |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
558 |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
559 CheckNeedsProcessing(needsReconstruct2, needsReingest2, currentDbConfiguration, pluginStatus_.currentlyProcessingConfiguration); |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
560 needsFullProcessing = needsReconstruct2 || needsReingest2; // if the configuration has changed compared to the config being processed, we need a full processing again |
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
561 } |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
562 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
563 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
564 if (!needsProcessing) |
4961 | 565 { |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
566 OrthancPlugins::LogWarning("Housekeeper: everything has been processed already !"); |
4961 | 567 return; |
568 } | |
569 | |
5009
ed4ceb31bcf8
Housekeeper plugin: Fix resume of previous processing
Alain Mazy <am@osimis.io>
parents:
4993
diff
changeset
|
570 if (force_ || needsFullProcessing) |
4961 | 571 { |
572 if (force_) | |
573 { | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
574 OrthancPlugins::LogWarning("Housekeeper: forcing execution -> will perform housekeeping"); |
4961 | 575 } |
576 else | |
577 { | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
578 OrthancPlugins::LogWarning("Housekeeper: the DB configuration has changed since last run, will reprocess the whole DB !"); |
4961 | 579 } |
580 | |
581 Json::Value changes; | |
582 OrthancPlugins::RestApiGet(changes, "/changes?last", false); | |
583 | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
584 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
585 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
586 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
587 pluginStatus_.lastProcessedChange = 0; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
588 pluginStatus_.lastChangeToProcess = changes["Last"].asInt64(); // the last change is the last change at the time we start. We assume that every new ingested file will be constructed correctly |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
589 pluginStatus_.lastTimeStarted = boost::posix_time::microsec_clock::universal_time(); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
590 } |
4961 | 591 } |
592 else | |
593 { | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
594 OrthancPlugins::LogWarning("Housekeeper: the DB configuration has not changed since last run, will continue processing changes"); |
4961 | 595 } |
596 | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
597 bool completed = false; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
598 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
599 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
600 completed = pluginStatus_.lastChangeToProcess == 0; // if the DB is empty at start, no need to process anyting |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
601 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
602 |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
603 bool loggedNotRightPeriodChangeMessage = false; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
604 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
605 while (!workerThreadShouldStop_ && !completed) |
4961 | 606 { |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
607 if (runningPeriods_.isInPeriod()) |
4961 | 608 { |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
609 completed = ProcessChanges(needsReconstruct, needsReingest, currentDbConfiguration); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
610 SaveStatusInDb(); |
4961 | 611 |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
612 if (!completed) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
613 { |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
614 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
615 |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
616 OrthancPlugins::LogInfo("Housekeeper: processed changes " + |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
617 boost::lexical_cast<std::string>(pluginStatus_.lastProcessedChange) + |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
618 " / " + boost::lexical_cast<std::string>(pluginStatus_.lastChangeToProcess)); |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
619 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
620 boost::this_thread::sleep(boost::posix_time::milliseconds(throttleDelay_ * 100)); // wait 1/10 of the delay between changes |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
621 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
622 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
623 loggedNotRightPeriodChangeMessage = false; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
624 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
625 else |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
626 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
627 if (!loggedNotRightPeriodChangeMessage) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
628 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
629 OrthancPlugins::LogInfo("Housekeeper: entering quiet period"); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
630 loggedNotRightPeriodChangeMessage = true; |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
631 } |
4961 | 632 } |
633 } | |
634 | |
635 if (completed) | |
636 { | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
637 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
638 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
639 pluginStatus_.lastProcessedConfiguration = currentDbConfiguration; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
640 pluginStatus_.currentlyProcessingConfiguration.Clear(); |
4961 | 641 |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
642 pluginStatus_.lastProcessedChange = -1; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
643 pluginStatus_.lastChangeToProcess = -1; |
4961 | 644 |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
645 SaveStatusInDb(); |
4961 | 646 |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
647 OrthancPluginLogWarning(OrthancPlugins::GetGlobalContext(), "Housekeeper: finished processing all changes"); |
4961 | 648 } |
649 } | |
650 | |
651 extern "C" | |
652 { | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
653 OrthancPluginErrorCode GetPluginStatus(OrthancPluginRestOutput* output, |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
654 const char* url, |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
655 const OrthancPluginHttpRequest* request) |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
656 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
657 if (request->method != OrthancPluginHttpMethod_Get) |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
658 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
659 OrthancPlugins::AnswerMethodNotAllowed(output, "GET"); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
660 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
661 else |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
662 { |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
663 boost::recursive_mutex::scoped_lock lock(pluginStatusMutex_); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
664 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
665 Json::Value status; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
666 pluginStatus_.ToJson(status); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
667 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
668 OrthancPlugins::AnswerJson(status, output); |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
669 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
670 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
671 return OrthancPluginErrorCode_Success; |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
672 } |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
673 |
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
674 |
4961 | 675 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType, |
676 OrthancPluginResourceType resourceType, | |
677 const char* resourceId) | |
678 { | |
679 switch (changeType) | |
680 { | |
681 case OrthancPluginChangeType_OrthancStarted: | |
682 { | |
683 workerThread_.reset(new boost::thread(WorkerThread)); | |
684 return OrthancPluginErrorCode_Success; | |
685 } | |
686 case OrthancPluginChangeType_OrthancStopped: | |
687 { | |
688 if (workerThread_ && workerThread_->joinable()) | |
689 { | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
690 workerThreadShouldStop_ = true; |
4961 | 691 workerThread_->join(); |
692 } | |
693 } | |
694 default: | |
695 return OrthancPluginErrorCode_Success; | |
696 } | |
697 } | |
698 | |
699 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) | |
700 { | |
701 OrthancPlugins::SetGlobalContext(c); | |
702 | |
703 /* Check the version of the Orthanc core */ | |
704 if (OrthancPluginCheckVersion(c) == 0) | |
705 { | |
706 OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, | |
707 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | |
708 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
709 return -1; | |
710 } | |
711 | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
712 OrthancPlugins::LogWarning("Housekeeper plugin is initializing"); |
4961 | 713 OrthancPluginSetDescription(c, "Optimizes your DB and storage."); |
714 | |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
715 OrthancPlugins::OrthancConfiguration orthancConfiguration; |
4961 | 716 |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
717 OrthancPlugins::OrthancConfiguration housekeeper; |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
718 orthancConfiguration.GetSection(housekeeper, "Housekeeper"); |
4961 | 719 |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
720 bool enabled = housekeeper.GetBooleanValue("Enable", false); |
4961 | 721 if (enabled) |
722 { | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
723 /* |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
724 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
725 "Housekeeper": { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
726 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
727 // Enables/disables the plugin |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
728 "Enable": false, |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
729 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
730 // the Global Prooperty ID in which the plugin progress |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
731 // is stored. Must be > 1024 and must not be used by |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
732 // another plugin |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
733 "GlobalPropertyId": 1025, |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
734 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
735 // Forces execution even if the plugin did not detect |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
736 // any changes in configuration |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
737 "Force": false, |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
738 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
739 // Delay (in seconds) between reconstruction of 2 studies |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
740 // This avoids overloading Orthanc with the housekeeping |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
741 // process and leaves room for other operations. |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
742 "ThrottleDelay": 5, |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
743 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
744 // Runs the plugin only at certain period of time. |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
745 // If not specified, the plugin runs all the time |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
746 // Examples: |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
747 // to run between 0AM and 6AM everyday + every night |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
748 // from 8PM to 12PM and 24h a day on the weekend: |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
749 // "Schedule": { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
750 // "Monday": ["0-6", "20-24"], |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
751 // "Tuesday": ["0-6", "20-24"], |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
752 // "Wednesday": ["0-6", "20-24"], |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
753 // "Thursday": ["0-6", "20-24"], |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
754 // "Friday": ["0-6", "20-24"], |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
755 // "Saturday": ["0-24"], |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
756 // "Sunday": ["0-24"] |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
757 // }, |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
758 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
759 // configure events that can trigger a housekeeping processing |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
760 "Triggers" : { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
761 "StorageCompressionChange": true, |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
762 "MainDicomTagsChange": true, |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
763 "UnnecessaryDicomAsJsonFiles": true |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
764 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
765 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
766 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
767 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
768 */ |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
769 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
770 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
771 globalPropertyId_ = housekeeper.GetIntegerValue("GlobalPropertyId", 1025); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
772 force_ = housekeeper.GetBooleanValue("Force", false); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
773 throttleDelay_ = housekeeper.GetUnsignedIntegerValue("ThrottleDelay", 5); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
774 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
775 if (housekeeper.GetJson().isMember("Triggers")) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
776 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
777 triggerOnStorageCompressionChange_ = housekeeper.GetBooleanValue("StorageCompressionChange", true); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
778 |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
779 triggerOnMainDicomTagsChange_ = housekeeper.GetBooleanValue("MainDicomTagsChange", true); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
780 triggerOnUnnecessaryDicomAsJsonFiles_ = housekeeper.GetBooleanValue("UnnecessaryDicomAsJsonFiles", true); |
4988
8fba26292a9f
Housekeeper plugin: finalizing + integration tests ok
Alain Mazy <am@osimis.io>
parents:
4982
diff
changeset
|
781 triggerOnIngestTranscodingChange_ = housekeeper.GetBooleanValue("IngestTranscodingChange", true); |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
782 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
783 |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
784 if (housekeeper.GetJson().isMember("Schedule")) |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
785 { |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
786 runningPeriods_.load(housekeeper.GetJson()["Schedule"]); |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
787 } |
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
788 |
4961 | 789 OrthancPluginRegisterOnChangeCallback(c, OnChangeCallback); |
5035 | 790 OrthancPluginRegisterRestCallback(c, "/housekeeper/status", GetPluginStatus); // for bacward compatiblity with version 1.11.0 |
791 OrthancPluginRegisterRestCallback(c, "/plugins/housekeeper/status", GetPluginStatus); | |
4961 | 792 } |
793 else | |
794 { | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
795 OrthancPlugins::LogWarning("Housekeeper plugin is disabled by the configuration file"); |
4961 | 796 } |
797 | |
798 return 0; | |
799 } | |
800 | |
801 | |
802 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
803 { | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
804 OrthancPlugins::LogWarning("Housekeeper plugin is finalizing"); |
4961 | 805 } |
806 | |
807 | |
808 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
809 { | |
4979
f316413027fd
renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents:
4961
diff
changeset
|
810 return "housekeeper"; |
4961 | 811 } |
812 | |
813 | |
814 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
815 { | |
4981 | 816 return HOUSEKEEPER_VERSION; |
4961 | 817 } |
818 } |