Merge branch 'feature/v1-actions-execute-command-8034-deadline-timer' into feature/v1-actions-execute-command-8034

refs #8034
This commit is contained in:
Alexander A. Klimov 2020-09-15 18:14:01 +02:00
commit fe4a44096a
2 changed files with 39 additions and 0 deletions

View File

@ -20,6 +20,8 @@ boost::signals2::signal<void (const Checkable::Ptr&, const String&, double, cons
boost::signals2::signal<void (const Checkable::Ptr&, double)> Checkable::OnFlappingChange;
static Timer::Ptr l_CheckablesFireSuppressedNotifications;
static Timer::Ptr l_CleanDeadlinedExecutions;
thread_local std::function<void(const Value& commandLine, const ProcessResult&)> Checkable::ExecuteCommandProcessFinishedHandler;
void Checkable::StaticInitialize()
@ -79,6 +81,11 @@ void Checkable::Start(bool runtimeCreated)
l_CheckablesFireSuppressedNotifications->SetInterval(5);
l_CheckablesFireSuppressedNotifications->OnTimerExpired.connect(&Checkable::FireSuppressedNotifications);
l_CheckablesFireSuppressedNotifications->Start();
l_CleanDeadlinedExecutions = new Timer();
l_CleanDeadlinedExecutions->SetInterval(300);
l_CleanDeadlinedExecutions->OnTimerExpired.connect(&Checkable::CleanDeadlinedExecutions);
l_CleanDeadlinedExecutions->Start();
});
}
@ -258,3 +265,34 @@ void Checkable::ValidateMaxCheckAttempts(const Lazy<int>& lvalue, const Validati
if (lvalue() <= 0)
BOOST_THROW_EXCEPTION(ValidationError(this, { "max_check_attempts" }, "Value must be greater than 0."));
}
void Checkable::CleanDeadlinedExecutions(const Timer * const&)
{
double now = Utility::GetTime();
Dictionary::Ptr executions;
Dictionary::Ptr execution;
for (auto& host : ConfigType::GetObjectsByType<Host>()) {
executions = host->GetExecutions();
if (executions) {
for (const String& key : executions->GetKeys()) {
execution = executions->Get(key);
if (execution->Contains("deadline") && now > execution->Get("deadline")) {
executions->Remove(key);
}
}
}
}
for (auto& service : ConfigType::GetObjectsByType<Service>()) {
executions = service->GetExecutions();
if (executions) {
for (const String& key : executions->GetKeys()) {
execution = executions->Get(key);
if (execution->Contains("deadline") && now > execution->Get("deadline")) {
executions->Remove(key);
}
}
}
}
}

View File

@ -205,6 +205,7 @@ private:
static void NotifyDowntimeEnd(const Downtime::Ptr& downtime);
static void FireSuppressedNotifications(const Timer * const&);
static void CleanDeadlinedExecutions(const Timer * const&);
/* Comments */
std::set<Comment::Ptr> m_Comments;