From d2ecb7f49c3f3b60e3d1f297fd033071a02cfa9a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 17 Mar 2026 11:48:34 +0000 Subject: Execute jobs even when processing incoming logs Jobs run on background threads now, so we can happily run them even when we're busy. --- src/ingestor.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/ingestor.cpp') diff --git a/src/ingestor.cpp b/src/ingestor.cpp index 988fd4d..950641b 100644 --- a/src/ingestor.cpp +++ b/src/ingestor.cpp @@ -135,8 +135,9 @@ namespace WebStat { { curl_waitfd logIn {.fd = fileno(input), .events = CURL_WAIT_POLLIN, .revents = 0}; - for (int interesting = 0; - curl_multi_poll(curl.get(), &logIn, 1, settings.idleJobsAfter, &interesting) == CURLM_OK;) { + const auto curlTimeOut = static_cast( + std::chrono::duration_cast(settings.checkJobsAfter).count()); + while (curl_multi_poll(curl.get(), &logIn, 1, curlTimeOut, nullptr) == CURLM_OK) { if (logIn.revents) { if (auto line = scn::scan(input, "{:[^\n]}\n")) { linesRead++; @@ -146,8 +147,8 @@ namespace WebStat { break; } } - else if (!interesting) { - runJobsIdle(); + if (expiredThenSet(lastCheckedJobs, settings.checkJobsAfter)) { + runJobsAsNeeded(); } if (!curlOperations.empty()) { handleCurlOperations(); @@ -218,10 +219,10 @@ namespace WebStat { } void - Ingestor::runJobsIdle() + Ingestor::runJobsAsNeeded() { auto runJobAsNeeded = [this, now = Job::LastRunTime::clock::now()](Job & job, auto freq) { - if (!job.currentRun && job.lastRun + freq < now) { + if (!job.currentRun && expired(job.lastRun, freq, now)) { job.currentRun.emplace([this, now, freq, &job]() { try { (this->*job.impl)(); -- cgit v1.3