blob: dda0832c5b7066306ec0c372373f0c87725f7b5a (
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "backoff.h"
#include <vespa/vespalib/util/signalhandler.h>
namespace slobrok::api {
namespace {
constexpr size_t num_warn_intervals = 5;
const double warn_intervals[num_warn_intervals] = { 1.0, 10.0, 60.0, 600.0, 3600.0 };
}
BackOff::BackOff() { reset(); }
void BackOff::reset() {
_time = 0.0;
_since_last_warn = 0.0;
_nextwarn_idx = 0;
}
double BackOff::get() {
_since_last_warn += _time;
if (_time < 20.0) {
_time += 0.5;
}
return _time;
}
bool BackOff::shouldWarn() {
if (vespalib::SignalHandler::TERM.check()) {
return false;
}
if (_since_last_warn >= warn_intervals[_nextwarn_idx]) {
if (_nextwarn_idx + 1 < num_warn_intervals) {
++_nextwarn_idx;
}
_since_last_warn = 0.0;
return true;
}
return false;
}
} // namespace slobrok::api
|