| 2560 | } |
| 2561 | |
| 2562 | void IcingaDB::ForwardHistoryEntries() |
| 2563 | { |
| 2564 | using clock = std::chrono::steady_clock; |
| 2565 | |
| 2566 | const std::chrono::seconds logInterval (10); |
| 2567 | auto nextLog (clock::now() + logInterval); |
| 2568 | |
| 2569 | auto logPeriodically ([this, logInterval, &nextLog]() { |
| 2570 | if (clock::now() > nextLog) { |
| 2571 | nextLog += logInterval; |
| 2572 | |
| 2573 | auto size (m_HistoryBulker.Size()); |
| 2574 | |
| 2575 | Log(size > m_HistoryBulker.GetBulkSize() ? LogInformation : LogNotice, "IcingaDB") |
| 2576 | << "Pending history queries: " << size; |
| 2577 | } |
| 2578 | }); |
| 2579 | |
| 2580 | for (;;) { |
| 2581 | logPeriodically(); |
| 2582 | |
| 2583 | auto haystack (m_HistoryBulker.ConsumeMany()); |
| 2584 | |
| 2585 | if (haystack.empty()) { |
| 2586 | if (!GetActive()) { |
| 2587 | break; |
| 2588 | } |
| 2589 | |
| 2590 | continue; |
| 2591 | } |
| 2592 | |
| 2593 | uintmax_t attempts = 0; |
| 2594 | |
| 2595 | auto logFailure ([&haystack, &attempts](const char* err = nullptr) { |
| 2596 | Log msg (LogNotice, "IcingaDB"); |
| 2597 | |
| 2598 | msg << "history: " << haystack.size() << " queries failed temporarily (attempt #" << ++attempts << ")"; |
| 2599 | |
| 2600 | if (err) { |
| 2601 | msg << ": " << err; |
| 2602 | } |
| 2603 | }); |
| 2604 | |
| 2605 | for (;;) { |
| 2606 | logPeriodically(); |
| 2607 | |
| 2608 | if (m_Rcon && m_Rcon->IsConnected()) { |
| 2609 | try { |
| 2610 | m_Rcon->GetResultsOfQueries(haystack, {0, 0, haystack.size()}); |
| 2611 | break; |
| 2612 | } catch (const std::exception& ex) { |
| 2613 | logFailure(ex.what()); |
| 2614 | } catch (...) { |
| 2615 | logFailure(); |
| 2616 | } |
| 2617 | } else { |
| 2618 | logFailure("not connected to Redis"); |
| 2619 | } |
nothing calls this directly
no test coverage detected