annotate OrthancServer/Plugins/Samples/Housekeeper/Plugin.cpp @ 4979:f316413027fd more-tags

renamed DbOptizer into Housekeeper + add Scheduler & triggers
author Alain Mazy <am@osimis.io>
date Mon, 25 Apr 2022 15:30:51 +0200
parents OrthancServer/Plugins/Samples/DbOptimizer/Plugin.cpp@1b76853e1797
children d0c34145320c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
1 /**
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
7 *
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
11 * License, or (at your option) any later version.
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
12 *
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
16 * General Public License for more details.
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
17 *
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
20 **/
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
21
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
22
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
23 #include "../../../../OrthancFramework/Sources/Compatibility.h"
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
24 #include "../Common/OrthancPluginCppWrapper.h"
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
25
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
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>
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
28 #include <json/value.h>
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
29 #include <json/writer.h>
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
30 #include <string.h>
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
31 #include <iostream>
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
32 #include <algorithm>
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
33 #include <map>
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
34 #include <list>
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
35 #include <time.h>
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
36
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
37 static int globalPropertyId_ = 0;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
38 static bool force_ = false;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
39 static uint throttleDelay_ = 0;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
40 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
41 static bool workerThreadShouldStop_ = false;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
42 static bool triggerOnStorageCompressionChange_ = true;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
43 static bool triggerOnMainDicomTagsChange_ = true;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
44 static bool triggerOnUnnecessaryDicomAsJsonFiles_ = true;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
45
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
46
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
47 struct RunningPeriod
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 int fromHour_;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
50 int toHour_;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
51 int weekday_;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
52
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
53 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
54 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
55 if (weekday == "Monday")
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
56 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
57 weekday_ = 1;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
58 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
59 else if (weekday == "Tuesday")
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
60 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
61 weekday_ = 2;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
62 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
63 else if (weekday == "Wednesday")
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
64 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
65 weekday_ = 3;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
66 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
67 else if (weekday == "Thursday")
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
68 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
69 weekday_ = 4;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
70 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
71 else if (weekday == "Friday")
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
72 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
73 weekday_ = 5;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
74 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
75 else if (weekday == "Saturday")
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
76 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
77 weekday_ = 6;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
78 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
79 else if (weekday == "Sunday")
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
80 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
81 weekday_ = 0;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
82 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
83 else
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
84 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
85 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
86 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat);
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
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
89 std::vector<std::string> hours;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
90 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
91
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
92 fromHour_ = boost::lexical_cast<int>(hours[0]);
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
93 toHour_ = boost::lexical_cast<int>(hours[1]);
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
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
96 bool isInPeriod() const
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 time_t now = time(NULL);
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
99 tm* nowLocalTime = localtime(&now);
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 if (nowLocalTime->tm_wday != weekday_)
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
102 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
103 return false;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
104 }
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 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
107 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
108 return true;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
109 }
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 false;
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
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
115 struct RunningPeriods
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 std::list<RunningPeriod> runningPeriods_;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
118
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
119 void load(const Json::Value& scheduleConfiguration)
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 // "Monday": ["0-6", "20-24"],
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 Json::Value::Members names = scheduleConfiguration.getMemberNames();
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 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
126 it != names.end(); it++)
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
127 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
128 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
129 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
130 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
131 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
132 }
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
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
135 bool isInPeriod()
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 if (runningPeriods_.size() == 0)
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 return true; // if no config: always run
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
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
142 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
143 it != runningPeriods_.end(); it++)
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 if (it->isInPeriod())
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
146 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
147 return true;
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 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
150 return false;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
151 }
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 RunningPeriods runningPeriods_;
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
155
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
156 struct DbConfiguration
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
157 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
158 std::string orthancVersion;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
159 std::map<OrthancPluginResourceType, std::string> mainDicomTagsSignature;
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
160 bool storageCompressionEnabled;
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
161
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
162 DbConfiguration()
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
163 : storageCompressionEnabled(false)
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
164 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
165 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
166
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
167 bool IsDefined() const
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
168 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
169 return !orthancVersion.empty() && mainDicomTagsSignature.size() == 4;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
170 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
171
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
172 void Clear()
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
173 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
174 orthancVersion.clear();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
175 mainDicomTagsSignature.clear();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
176 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
177
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
178 void ToJson(Json::Value& target)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
179 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
180 if (!IsDefined())
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
181 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
182 target = Json::nullValue;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
183 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
184 else
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
185 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
186 Json::Value signatures;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
187
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
188 target = Json::objectValue;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
189
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
190 // default main dicom tags signature are the one from Orthanc 1.4.2 (last time the list was changed):
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
191 signatures["Patient"] = mainDicomTagsSignature[OrthancPluginResourceType_Patient];
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
192 signatures["Study"] = mainDicomTagsSignature[OrthancPluginResourceType_Study];
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
193 signatures["Series"] = mainDicomTagsSignature[OrthancPluginResourceType_Series];
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
194 signatures["Instance"] = mainDicomTagsSignature[OrthancPluginResourceType_Instance];
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
195
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
196 target["MainDicomTagsSignature"] = signatures;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
197 target["OrthancVersion"] = orthancVersion;
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
198 target["StorageCompressionEnabled"] = storageCompressionEnabled;
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
199 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
200 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
201
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
202 void FromJson(Json::Value& source)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
203 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
204 if (!source.isNull())
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
205 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
206 orthancVersion = source["OrthancVersion"].asString();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
207
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
208 const Json::Value& signatures = source["MainDicomTagsSignature"];
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
209 mainDicomTagsSignature[OrthancPluginResourceType_Patient] = signatures["Patient"].asString();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
210 mainDicomTagsSignature[OrthancPluginResourceType_Study] = signatures["Study"].asString();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
211 mainDicomTagsSignature[OrthancPluginResourceType_Series] = signatures["Series"].asString();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
212 mainDicomTagsSignature[OrthancPluginResourceType_Instance] = signatures["Instance"].asString();
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
213
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
214 storageCompressionEnabled = source["StorageCompressionEnabled"].asBool();
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
215 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
216 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
217 };
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
218
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
219 struct PluginStatus
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
220 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
221 int statusVersion;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
222 int64_t lastProcessedChange;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
223 int64_t lastChangeToProcess;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
224
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
225 DbConfiguration currentlyProcessingConfiguration; // last configuration being processed (has not reached last change yet)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
226 DbConfiguration lastProcessedConfiguration; // last configuration that has been fully processed (till last change)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
227
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
228 PluginStatus()
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
229 : statusVersion(1),
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
230 lastProcessedChange(-1),
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
231 lastChangeToProcess(-1)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
232 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
233 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
234
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
235 void ToJson(Json::Value& target)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
236 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
237 target = Json::objectValue;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
238
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
239 target["Version"] = statusVersion;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
240 target["LastProcessedChange"] = Json::Value::Int64(lastProcessedChange);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
241 target["LastChangeToProcess"] = Json::Value::Int64(lastChangeToProcess);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
242
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
243 currentlyProcessingConfiguration.ToJson(target["CurrentlyProcessingConfiguration"]);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
244 lastProcessedConfiguration.ToJson(target["LastProcessedConfiguration"]);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
245 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
246
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
247 void FromJson(Json::Value& source)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
248 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
249 statusVersion = source["Version"].asInt();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
250 lastProcessedChange = source["LastProcessedChange"].asInt64();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
251 lastChangeToProcess = source["LastChangeToProcess"].asInt64();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
252
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
253 Json::Value& current = source["CurrentlyProcessingConfiguration"];
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
254 Json::Value& last = source["LastProcessedConfiguration"];
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
255
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
256 currentlyProcessingConfiguration.FromJson(current);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
257 lastProcessedConfiguration.FromJson(last);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
258 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
259 };
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
260
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
261
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
262 static void ReadStatusFromDb(PluginStatus& pluginStatus)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
263 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
264 OrthancPlugins::OrthancString globalPropertyContent;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
265
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
266 globalPropertyContent.Assign(OrthancPluginGetGlobalProperty(OrthancPlugins::GetGlobalContext(),
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
267 globalPropertyId_,
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
268 ""));
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
269
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
270 if (!globalPropertyContent.IsNullOrEmpty())
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
271 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
272 Json::Value jsonStatus;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
273 globalPropertyContent.ToJson(jsonStatus);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
274 pluginStatus.FromJson(jsonStatus);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
275 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
276 else
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
277 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
278 // default config
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
279 pluginStatus.statusVersion = 1;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
280 pluginStatus.lastProcessedChange = -1;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
281 pluginStatus.lastChangeToProcess = -1;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
282
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
283 pluginStatus.currentlyProcessingConfiguration.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)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
284
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
285 // default main dicom tags signature are the one from Orthanc 1.4.2 (last time the list was changed):
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
286 pluginStatus.currentlyProcessingConfiguration.mainDicomTagsSignature[OrthancPluginResourceType_Patient] = "0010,0010;0010,0020;0010,0030;0010,0040;0010,1000";
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
287 pluginStatus.currentlyProcessingConfiguration.mainDicomTagsSignature[OrthancPluginResourceType_Study] = "0008,0020;0008,0030;0008,0050;0008,0080;0008,0090;0008,1030;0020,000d;0020,0010;0032,1032;0032,1060";
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
288 pluginStatus.currentlyProcessingConfiguration.mainDicomTagsSignature[OrthancPluginResourceType_Series] = "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";
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
289 pluginStatus.currentlyProcessingConfiguration.mainDicomTagsSignature[OrthancPluginResourceType_Instance] = "0008,0012;0008,0013;0008,0018;0020,0012;0020,0013;0020,0032;0020,0037;0020,0100;0020,4000;0028,0008;0054,1330";
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
290 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
291 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
292
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
293 static void SaveStatusInDb(PluginStatus& pluginStatus)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
294 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
295 Json::Value jsonStatus;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
296 pluginStatus.ToJson(jsonStatus);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
297
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
298 Json::StreamWriterBuilder builder;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
299 builder.settings_["indentation"] = " ";
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
300 std::string serializedStatus = Json::writeString(builder, jsonStatus);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
301
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
302 OrthancPluginSetGlobalProperty(OrthancPlugins::GetGlobalContext(),
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
303 globalPropertyId_,
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
304 serializedStatus.c_str());
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
305 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
306
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
307 static void GetCurrentDbConfiguration(DbConfiguration& configuration)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
308 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
309 Json::Value signatures;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
310 Json::Value systemInfo;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
311
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
312 OrthancPlugins::RestApiGet(systemInfo, "/system", false);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
313 configuration.mainDicomTagsSignature[OrthancPluginResourceType_Patient] = systemInfo["MainDicomTags"]["Patient"].asString();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
314 configuration.mainDicomTagsSignature[OrthancPluginResourceType_Study] = systemInfo["MainDicomTags"]["Study"].asString();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
315 configuration.mainDicomTagsSignature[OrthancPluginResourceType_Series] = systemInfo["MainDicomTags"]["Series"].asString();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
316 configuration.mainDicomTagsSignature[OrthancPluginResourceType_Instance] = systemInfo["MainDicomTags"]["Instance"].asString();
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
317 configuration.storageCompressionEnabled = systemInfo["StorageCompression"].asBool();
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
318
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
319 configuration.orthancVersion = OrthancPlugins::GetGlobalContext()->orthancVersion;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
320 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
321
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
322 static bool NeedsProcessing(const DbConfiguration& current, const DbConfiguration& last)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
323 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
324 if (!last.IsDefined())
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
325 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
326 return true;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
327 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
328
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
329 const char* lastVersion = last.orthancVersion.c_str();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
330 const std::map<OrthancPluginResourceType, std::string>& lastTags = last.mainDicomTagsSignature;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
331 const std::map<OrthancPluginResourceType, std::string>& currentTags = current.mainDicomTagsSignature;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
332 bool needsProcessing = false;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
333
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
334 if (!OrthancPlugins::CheckMinimalVersion(lastVersion, 1, 9, 1))
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
335 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
336 if (triggerOnUnnecessaryDicomAsJsonFiles_)
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
337 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
338 OrthancPlugins::LogWarning("Housekeeper: your storage might still contain some dicom-as-json files -> will perform housekeeping");
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
339 needsProcessing = true;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
340 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
341 else
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
342 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
343 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
344 }
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
345 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
346
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
347 if (lastTags.at(OrthancPluginResourceType_Patient) != currentTags.at(OrthancPluginResourceType_Patient))
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
348 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
349 if (triggerOnMainDicomTagsChange_)
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
350 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
351 OrthancPlugins::LogWarning("Housekeeper: Patient main dicom tags have changed, -> will perform housekeeping");
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
352 needsProcessing = true;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
353 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
354 else
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
355 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
356 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
357 }
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
358 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
359
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
360 if (lastTags.at(OrthancPluginResourceType_Study) != currentTags.at(OrthancPluginResourceType_Study))
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
361 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
362 if (triggerOnMainDicomTagsChange_)
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
363 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
364 OrthancPlugins::LogWarning("Housekeeper: Study main dicom tags have changed, -> will perform housekeeping");
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
365 needsProcessing = true;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
366 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
367 else
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
368 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
369 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
370 }
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
371 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
372
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
373 if (lastTags.at(OrthancPluginResourceType_Series) != currentTags.at(OrthancPluginResourceType_Series))
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
374 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
375 if (triggerOnMainDicomTagsChange_)
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
376 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
377 OrthancPlugins::LogWarning("Housekeeper: Series main dicom tags have changed, -> will perform housekeeping");
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
378 needsProcessing = true;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
379 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
380 else
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
381 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
382 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
383 }
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
384 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
385
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
386 if (lastTags.at(OrthancPluginResourceType_Instance) != currentTags.at(OrthancPluginResourceType_Instance))
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
387 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
388 if (triggerOnMainDicomTagsChange_)
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
389 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
390 OrthancPlugins::LogWarning("Housekeeper: Instance main dicom tags have changed, -> will perform housekeeping");
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
391 needsProcessing = true;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
392 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
393 else
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
394 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
395 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
396 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
397 }
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 if (current.storageCompressionEnabled != last.storageCompressionEnabled)
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
400 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
401 if (triggerOnStorageCompressionChange_)
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
402 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
403 if (current.storageCompressionEnabled)
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
404 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
405 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
406 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
407 else
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
408 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
409 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
410 }
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 needsProcessing = true;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
413 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
414 else
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
415 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
416 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
417 }
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
418 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
419
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
420 return needsProcessing;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
421 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
422
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
423 static bool ProcessChanges(PluginStatus& pluginStatus, const DbConfiguration& currentDbConfiguration)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
424 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
425 Json::Value changes;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
426
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
427 pluginStatus.currentlyProcessingConfiguration = currentDbConfiguration;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
428
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
429 OrthancPlugins::RestApiGet(changes, "/changes?since=" + boost::lexical_cast<std::string>(pluginStatus.lastProcessedChange) + "&limit=100", false);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
430
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
431 for (Json::ArrayIndex i = 0; i < changes["Changes"].size(); i++)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
432 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
433 const Json::Value& change = changes["Changes"][i];
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
434 int64_t seq = change["Seq"].asInt64();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
435
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
436 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
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
437 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
438 Json::Value result;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
439 OrthancPlugins::RestApiPost(result, "/studies/" + change["ID"].asString() + "/reconstruct", std::string(""), false);
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
440 boost::this_thread::sleep(boost::posix_time::milliseconds(throttleDelay_ * 1000));
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
441 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
442
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
443 if (seq >= pluginStatus.lastChangeToProcess) // we are done !
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
444 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
445 return true;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
446 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
447
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
448 pluginStatus.lastProcessedChange = seq;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
449 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
450
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
451 return false;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
452 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
453
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
454
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
455 static void WorkerThread()
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
456 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
457 PluginStatus pluginStatus;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
458 DbConfiguration currentDbConfiguration;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
459
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
460 OrthancPluginLogWarning(OrthancPlugins::GetGlobalContext(), "Starting Housekeeper worker thread");
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
461
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
462 ReadStatusFromDb(pluginStatus);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
463 GetCurrentDbConfiguration(currentDbConfiguration);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
464
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
465 if (!NeedsProcessing(currentDbConfiguration, pluginStatus.lastProcessedConfiguration))
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
466 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
467 OrthancPlugins::LogWarning("Housekeeper: everything has been processed already !");
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
468 return;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
469 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
470
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
471 if (force_ || NeedsProcessing(currentDbConfiguration, pluginStatus.currentlyProcessingConfiguration))
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
472 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
473 if (force_)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
474 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
475 OrthancPlugins::LogWarning("Housekeeper: forcing execution -> will perform housekeeping");
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
476 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
477 else
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
478 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
479 OrthancPlugins::LogWarning("Housekeeper: the DB configuration has changed since last run, will reprocess the whole DB !");
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
480 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
481
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
482 Json::Value changes;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
483 OrthancPlugins::RestApiGet(changes, "/changes?last", false);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
484
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
485 pluginStatus.lastProcessedChange = 0;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
486 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
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
487 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
488 else
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
489 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
490 OrthancPlugins::LogWarning("Housekeeper: the DB configuration has not changed since last run, will continue processing changes");
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
491 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
492
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
493 bool completed = pluginStatus.lastChangeToProcess == 0; // if the DB is empty at start, no need to process anyting
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
494 bool loggedNotRightPeriodChangeMessage = false;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
495
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
496 while (!workerThreadShouldStop_ && !completed)
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
497 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
498 if (runningPeriods_.isInPeriod())
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
499 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
500 completed = ProcessChanges(pluginStatus, currentDbConfiguration);
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
501 SaveStatusInDb(pluginStatus);
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
502
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
503 if (!completed)
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
504 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
505 OrthancPlugins::LogInfo("Housekeeper: processed changes " +
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
506 boost::lexical_cast<std::string>(pluginStatus.lastProcessedChange) +
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
507 " / " + boost::lexical_cast<std::string>(pluginStatus.lastChangeToProcess));
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
508
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
509 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
510 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
511
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
512 loggedNotRightPeriodChangeMessage = false;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
513 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
514 else
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
515 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
516 if (!loggedNotRightPeriodChangeMessage)
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
517 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
518 OrthancPlugins::LogInfo("Housekeeper: entering quiet period");
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
519 loggedNotRightPeriodChangeMessage = true;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
520 }
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
521 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
522 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
523
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
524 if (completed)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
525 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
526 pluginStatus.lastProcessedConfiguration = currentDbConfiguration;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
527 pluginStatus.currentlyProcessingConfiguration.Clear();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
528
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
529 pluginStatus.lastProcessedChange = -1;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
530 pluginStatus.lastChangeToProcess = -1;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
531
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
532 SaveStatusInDb(pluginStatus);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
533
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
534 OrthancPluginLogWarning(OrthancPlugins::GetGlobalContext(), "Housekeeper: finished processing all changes");
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
535 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
536 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
537
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
538 extern "C"
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
539 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
540 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType,
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
541 OrthancPluginResourceType resourceType,
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
542 const char* resourceId)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
543 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
544 switch (changeType)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
545 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
546 case OrthancPluginChangeType_OrthancStarted:
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
547 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
548 workerThread_.reset(new boost::thread(WorkerThread));
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
549 return OrthancPluginErrorCode_Success;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
550 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
551 case OrthancPluginChangeType_OrthancStopped:
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
552 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
553 if (workerThread_ && workerThread_->joinable())
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
554 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
555 workerThreadShouldStop_ = true;
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
556 workerThread_->join();
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
557 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
558 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
559 default:
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
560 return OrthancPluginErrorCode_Success;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
561 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
562 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
563
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
564 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
565 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
566 OrthancPlugins::SetGlobalContext(c);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
567
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
568 /* Check the version of the Orthanc core */
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
569 if (OrthancPluginCheckVersion(c) == 0)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
570 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
571 OrthancPlugins::ReportMinimalOrthancVersion(ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
572 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
573 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
574 return -1;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
575 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
576
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
577 OrthancPlugins::LogWarning("Housekeeper plugin is initializing");
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
578 OrthancPluginSetDescription(c, "Optimizes your DB and storage.");
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
579
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
580 OrthancPlugins::OrthancConfiguration configuration;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
581
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
582 OrthancPlugins::OrthancConfiguration housekeeper;
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
583 configuration.GetSection(housekeeper, "Housekeeper");
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
584
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
585 bool enabled = housekeeper.GetBooleanValue("Enable", false);
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
586 if (enabled)
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
587 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
588 /*
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
589 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
590 "Housekeeper": {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
591
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
592 // Enables/disables the plugin
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
593 "Enable": false,
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
594
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
595 // 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
596 // 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
597 // another plugin
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
598 "GlobalPropertyId": 1025,
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
599
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
600 // 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
601 // any changes in configuration
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
602 "Force": false,
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
603
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
604 // 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
605 // This avoids overloading Orthanc with the housekeeping
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
606 // process and leaves room for other operations.
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
607 "ThrottleDelay": 5,
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
608
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
609 // 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
610 // 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
611 // Examples:
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
612 // 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
613 // 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
614 // "Schedule": {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
615 // "Monday": ["0-6", "20-24"],
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
616 // "Tuesday": ["0-6", "20-24"],
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
617 // "Wednesday": ["0-6", "20-24"],
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
618 // "Thursday": ["0-6", "20-24"],
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
619 // "Friday": ["0-6", "20-24"],
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
620 // "Saturday": ["0-24"],
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
621 // "Sunday": ["0-24"]
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
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
624 // 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
625 "Triggers" : {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
626 "StorageCompressionChange": true,
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
627 "MainDicomTagsChange": true,
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
628 "UnnecessaryDicomAsJsonFiles": true
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
629 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
630
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
631 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
632 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
633 */
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
634
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
635
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
636 globalPropertyId_ = housekeeper.GetIntegerValue("GlobalPropertyId", 1025);
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
637 force_ = housekeeper.GetBooleanValue("Force", false);
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
638 throttleDelay_ = housekeeper.GetUnsignedIntegerValue("ThrottleDelay", 5);
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
639
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
640 if (housekeeper.GetJson().isMember("Triggers"))
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
641 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
642 triggerOnStorageCompressionChange_ = housekeeper.GetBooleanValue("StorageCompressionChange", true);
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
643 triggerOnMainDicomTagsChange_ = housekeeper.GetBooleanValue("MainDicomTagsChange", true);
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
644 triggerOnUnnecessaryDicomAsJsonFiles_ = housekeeper.GetBooleanValue("UnnecessaryDicomAsJsonFiles", true);
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
645 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
646
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
647 if (housekeeper.GetJson().isMember("Schedule"))
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
648 {
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
649 runningPeriods_.load(housekeeper.GetJson()["Schedule"]);
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
650 }
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
651
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
652 OrthancPluginRegisterOnChangeCallback(c, OnChangeCallback);
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
653 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
654 else
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
655 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
656 OrthancPlugins::LogWarning("Housekeeper plugin is disabled by the configuration file");
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
657 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
658
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
659 return 0;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
660 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
661
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
662
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
663 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
664 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
665 OrthancPlugins::LogWarning("Housekeeper plugin is finalizing");
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
666 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
667
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
668
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
669 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
670 {
4979
f316413027fd renamed DbOptizer into Housekeeper + add Scheduler & triggers
Alain Mazy <am@osimis.io>
parents: 4961
diff changeset
671 return "housekeeper";
4961
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
672 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
673
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
674
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
675 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
676 {
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
677 return DB_OPTIMIZER_VERSION;
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
678 }
1b76853e1797 DbOptimizer plugin
Alain Mazy <am@osimis.io>
parents:
diff changeset
679 }