| 93 | } |
| 94 | |
| 95 | void CheckerComponent::CheckThreadProc() |
| 96 | { |
| 97 | Utility::SetThreadName("Check Scheduler"); |
| 98 | IcingaApplication::Ptr icingaApp = IcingaApplication::GetInstance(); |
| 99 | |
| 100 | std::unique_lock<std::mutex> lock(m_Mutex); |
| 101 | |
| 102 | for (;;) { |
| 103 | typedef boost::multi_index::nth_index<CheckableSet, 1>::type CheckTimeView; |
| 104 | CheckTimeView& idx = boost::get<1>(m_IdleCheckables); |
| 105 | |
| 106 | while (idx.begin() == idx.end() && !m_Stopped) |
| 107 | m_CV.wait(lock); |
| 108 | |
| 109 | if (m_Stopped) |
| 110 | break; |
| 111 | |
| 112 | auto it = idx.begin(); |
| 113 | CheckableScheduleInfo csi = *it; |
| 114 | |
| 115 | double wait = csi.NextCheck - Utility::GetTime(); |
| 116 | |
| 117 | //#ifdef I2_DEBUG |
| 118 | // Log(LogDebug, "CheckerComponent") |
| 119 | // << "Pending checks " << Checkable::GetPendingChecks() |
| 120 | // << " vs. max concurrent checks " << icingaApp->GetMaxConcurrentChecks() << "."; |
| 121 | //#endif /* I2_DEBUG */ |
| 122 | |
| 123 | if (Checkable::GetPendingChecks() >= icingaApp->GetMaxConcurrentChecks()) |
| 124 | wait = 0.5; |
| 125 | |
| 126 | if (wait > 0) { |
| 127 | /* Wait for the next check. */ |
| 128 | m_CV.wait_for(lock, std::chrono::duration<double>(wait)); |
| 129 | |
| 130 | continue; |
| 131 | } |
| 132 | |
| 133 | Checkable::Ptr checkable = csi.Object; |
| 134 | |
| 135 | m_IdleCheckables.erase(checkable); |
| 136 | |
| 137 | bool forced = checkable->GetForceNextCheck(); |
| 138 | bool check = true; |
| 139 | double nextCheck = -1; |
| 140 | |
| 141 | if (!forced) { |
| 142 | if (!checkable->IsReachable(DependencyCheckExecution)) { |
| 143 | Log(LogNotice, "CheckerComponent") |
| 144 | << "Skipping check for object '" << checkable->GetName() << "': Dependency failed."; |
| 145 | check = false; |
| 146 | } |
| 147 | |
| 148 | Host::Ptr host; |
| 149 | Service::Ptr service; |
| 150 | tie(host, service) = GetHostService(checkable); |
| 151 | |
| 152 | if (host && !service && (!checkable->GetEnableActiveChecks() || !icingaApp->GetEnableHostChecks())) { |
nothing calls this directly
no test coverage detected