diff options
| author | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-05-13 15:21:06 +0100 |
|---|---|---|
| committer | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-05-13 15:21:06 +0100 |
| commit | 3e7a1ce999b2223b321573de19cef840021f77f5 (patch) | |
| tree | 796ffd6c61f665c9dfdfb632fbfc2a5c91c1890f | |
| parent | 868446ad4d8ba33053b048dd4d82b6d4f5328f07 (diff) | |
| download | webstat-3e7a1ce999b2223b321573de19cef840021f77f5.tar.bz2 webstat-3e7a1ce999b2223b321573de19cef840021f77f5.tar.xz webstat-3e7a1ce999b2223b321573de19cef840021f77f5.zip | |
Fix checking of background job completeness
OK, this is on me. future::valid does not tell you if the thread has
completed and the result is ready. It tells you if there is some state
you can get() maybe later. Here we replace those checks with a 0s wait
and a test to see if the status is ready.
The exit steps are updated to reflect this. Calling reset will invoke
the future's destructor, which blocks until the thread is joined as
needed.
This should hopefully address the issue where the main thread would
still block if it attempted to runJobAsNeeded for a job that was still
running.
| -rw-r--r-- | src/ingestor.cpp | 8 | ||||
| -rw-r--r-- | test/test-ingest.cpp | 2 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/ingestor.cpp b/src/ingestor.cpp index 2c59866..e2c6f02 100644 --- a/src/ingestor.cpp +++ b/src/ingestor.cpp @@ -281,7 +281,9 @@ namespace WebStat { withCurlLock(&Ingestor::handleCurlOperations, this); } finishAllJobs(); - std::invoke(storeQueueLines.impl, this)(); + storeQueueLines.currentRun.reset(); + beginIngestQueuedLogLines(); + storeQueueLines.currentRun.reset(); std::ignore = parkLogLines(queuedLines); std::ignore = parkLogLines(processingLines); withCurlLock([this]() { @@ -300,7 +302,7 @@ namespace WebStat { Ingestor::beginIngestQueuedLogLines() { if (storeQueueLines.currentRun) { - if (!storeQueueLines.currentRun->valid()) { + if (storeQueueLines.currentRun->wait_for(std::chrono::seconds {}) != std::future_status::ready) { return {*storeQueueLines.currentRun, false}; } finalizeJob(storeQueueLines, {}, Job::LastRunTime::clock::now()); @@ -447,7 +449,7 @@ namespace WebStat { { auto runJobAsNeeded = [this, now = Job::LastRunTime::clock::now()](Job & job, auto freq) { if (job.currentRun) { - if (job.currentRun->valid()) { + if (job.currentRun->wait_for(std::chrono::seconds {}) == std::future_status::ready) { finalizeJob(job, freq, now); } } diff --git a/test/test-ingest.cpp b/test/test-ingest.cpp index 60338a2..0dad6e6 100644 --- a/test/test-ingest.cpp +++ b/test/test-ingest.cpp @@ -272,7 +272,7 @@ BOOST_AUTO_TEST_CASE(StoreLog, *boost::unit_test::depends_on("I/StoreLogLine")) WebStat::LogFile log {"/tmp/store-log-fixture.log", 10}; WebStat::FilePtr input {fopen(log.path.c_str(), "r")}; BOOST_REQUIRE(input); - ingestLog(input.get()); + BOOST_CHECK_NO_THROW(ingestLog(input.get())); BOOST_CHECK_EQUAL(stats.linesRead, 10); BOOST_CHECK_EQUAL(stats.linesParsed, 10); BOOST_CHECK_EQUAL(stats.linesParseFailed, 0); |
