diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-10-02 23:42:52 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-10-02 23:42:52 +0100 |
commit | 5aa9cca0d2ff25c541d7df3b63519c28eb75b656 (patch) | |
tree | c43e515374b08e2897b295c2706b8797cfc1e38b | |
parent | edfaf671d016f675a3a3b87d58d615a92e84148b (diff) | |
download | webstat-5aa9cca0d2ff25c541d7df3b63519c28eb75b656.tar.bz2 webstat-5aa9cca0d2ff25c541d7df3b63519c28eb75b656.tar.xz webstat-5aa9cca0d2ff25c541d7df3b63519c28eb75b656.zip |
Add point to execute scheduled jobs when idle
-rw-r--r-- | src/ingestor.cpp | 6 | ||||
-rw-r--r-- | src/ingestor.hpp | 4 | ||||
-rw-r--r-- | src/webstat_logger_main.cpp | 2 |
3 files changed, 11 insertions, 1 deletions
diff --git a/src/ingestor.cpp b/src/ingestor.cpp index 639eed0..cf49f52 100644 --- a/src/ingestor.cpp +++ b/src/ingestor.cpp @@ -127,7 +127,8 @@ namespace WebStat { { curl_waitfd logIn {.fd = fileno(input), .events = CURL_WAIT_POLLIN, .revents = 0}; - while (curl_multi_poll(curl.get(), &logIn, 1, INT_MAX, nullptr) == CURLM_OK) { + for (int interesting = 0; + curl_multi_poll(curl.get(), &logIn, 1, settings.idleJobsAfter, &interesting) == CURLM_OK;) { if (logIn.revents) { if (auto line = scn::scan<std::string>(input, "{:[^\n]}\n")) { linesRead++; @@ -140,6 +141,9 @@ namespace WebStat { else if (!curlOperations.empty()) { handleCurlOperations(); } + else if (!interesting) { + // do idle job things + } } while (!curlOperations.empty() && curl_multi_poll(curl.get(), nullptr, 0, INT_MAX, nullptr) == CURLM_OK) { handleCurlOperations(); diff --git a/src/ingestor.hpp b/src/ingestor.hpp index 42c6699..afd4a0f 100644 --- a/src/ingestor.hpp +++ b/src/ingestor.hpp @@ -13,12 +13,16 @@ #include <sys/utsname.h> namespace WebStat { + using namespace std::chrono; + using namespace std::chrono_literals; + struct IngestorSettings : Settings { std::string dbConnStr = "dbname=webstat user=webstat"; std::string userAgentAPI = "https://useragentstring.com"; std::filesystem::path fallbackDir = "/var/log/webstat"; unsigned int dbMax = 4; unsigned int dbKeep = 2; + int idleJobsAfter = duration_cast<milliseconds>(1min).count(); }; class Ingestor { diff --git a/src/webstat_logger_main.cpp b/src/webstat_logger_main.cpp index 9ce4e73..625afc6 100644 --- a/src/webstat_logger_main.cpp +++ b/src/webstat_logger_main.cpp @@ -40,6 +40,8 @@ main(int argc, char ** argv) "Number of write/read write DB connections to keep open") ("fallback.dir", po::value(&settings.fallbackDir)->default_value(settings.fallbackDir), "Path to write access logs to when the database is unavailable") + ("jobs.idle", po::value(&settings.idleJobsAfter)->default_value(settings.idleJobsAfter), + "Run idle when there's no activity for this period (ms)") ; // clang-format on po::variables_map optVars; |