diff --git a/cib/service.cpp b/cib/service.cpp index 6a4d4bc16..0a015112d 100644 --- a/cib/service.cpp +++ b/cib/service.cpp @@ -190,13 +190,18 @@ time_t Service::GetNextCheck(void) void Service::UpdateNextCheck(void) { - time_t now; + time_t now, previous, next, interval; + time(&now); + previous = GetNextCheck(); if (GetStateType() == StateTypeSoft) - SetNextCheck(now + GetRetryInterval()); + interval = GetRetryInterval(); else - SetNextCheck(now + GetCheckInterval()); + interval = GetCheckInterval(); + + next = now + ((now - previous) / interval + 1) * interval; + SetNextCheck(next); } void Service::SetChecker(const string& checker) diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 5157ed5df..d77d06390 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -104,6 +104,9 @@ void CheckerComponent::CheckCompletedHandler(Service service, const ScriptTask:: { service.RemoveTag("current_task"); + /* figure out when the next check is for this service */ + service.UpdateNextCheck(); + try { Variant vresult = task->GetResult(); @@ -135,14 +138,13 @@ void CheckerComponent::CheckCompletedHandler(Service service, const ScriptTask:: Logger::Write(LogWarning, "checker", msgbuf.str()); } - /* figure out when the next check is for this service */ - service.UpdateNextCheck(); - /* remove the service from the list of pending services; if it's not in the * list this was a manual (i.e. forced) check and we must not re-add the * service to the services list because it's already there. */ - if (m_PendingServices.find(service.GetConfigObject()) != m_PendingServices.end()) { - m_PendingServices.erase(service.GetConfigObject()); + set::iterator it; + it = m_PendingServices.find(service.GetConfigObject()); + if (it != m_PendingServices.end()) { + m_PendingServices.erase(it); m_Services.push(service); }