blob: a405a73fb3f4b437c9f9e42f60f85aafcec87c3e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include <reloadthread.h>
#include <logger.h>
namespace newsbeuter {
reloadthread::reloadthread(controller * c, configcontainer * cf) : ctrl(c), oldtime(0), waittime_sec(0), suppressed_first(false), cfg(cf) {
LOG(LOG_INFO,"reloadthread: waiting %u seconds between reloads",waittime_sec);
}
reloadthread::~reloadthread() { }
void reloadthread::run() {
for (;;) {
oldtime = time(NULL);
LOG(LOG_INFO,"reloadthread: starting reload");
waittime_sec = 60 * cfg->get_configvalue_as_int("reload-time");
if (waittime_sec == 0)
waittime_sec = 60;
if (cfg->get_configvalue_as_bool("auto-reload")) {
if (suppressed_first) {
ctrl->start_reload_all_thread();
} else {
suppressed_first = true;
if (!cfg->get_configvalue_as_bool("suppress-first-reload")) {
ctrl->start_reload_all_thread();
}
}
} else {
waittime_sec = 60; // if auto-reload is disabled, we poll every 60 seconds whether it changed.
}
time_t seconds_to_wait = 0;
if ((oldtime + waittime_sec) > time(NULL))
seconds_to_wait = oldtime + waittime_sec - time(NULL);
while (seconds_to_wait > 0) {
seconds_to_wait = ::sleep(seconds_to_wait);
}
}
}
}
|