diff options
| author | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-03-17 17:33:14 +0000 |
|---|---|---|
| committer | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-03-17 17:33:14 +0000 |
| commit | ae0ee6bbfb4dcd1f112876d0e7e5b3bcabdfb002 (patch) | |
| tree | 406c7383b4b710547688e9f46e48ae9f491b5912 /src | |
| parent | fc96582867acd2bcaef29feaae5c1193969d9a27 (diff) | |
| download | webstat-main.tar.bz2 webstat-main.tar.xz webstat-main.zip | |
Easier checking if a job has completed [successfully] and reseting state
for the next time.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ingestor.cpp | 12 | ||||
| -rw-r--r-- | src/ingestor.hpp | 3 |
2 files changed, 10 insertions, 5 deletions
diff --git a/src/ingestor.cpp b/src/ingestor.cpp index ba89991..692ddd2 100644 --- a/src/ingestor.cpp +++ b/src/ingestor.cpp @@ -223,17 +223,21 @@ namespace WebStat { Ingestor::runJobsAsNeeded() { auto runJobAsNeeded = [this, now = Job::LastRunTime::clock::now()](Job & job, auto freq) { - if (!job.currentRun && expired(job.lastRun, freq, now)) { - job.currentRun.emplace([this, now, freq, &job]() { + if (job.currentRun) { + if (job.currentRun->valid()) { try { - (this->*job.impl)(); + job.currentRun->get(); job.lastRun = now; } catch (const std::exception &) { // Error, retry in half the frequency job.lastRun = now - (freq / 2); } - }); + job.currentRun.reset(); + } + } + else if (expired(job.lastRun, freq, now)) { + job.currentRun.emplace(std::async(job.impl, this)); } }; runJobAsNeeded(ingestParkedLines, settings.freqIngestParkedLines); diff --git a/src/ingestor.hpp b/src/ingestor.hpp index c5628d6..0bf2297 100644 --- a/src/ingestor.hpp +++ b/src/ingestor.hpp @@ -8,6 +8,7 @@ #include <connection_fwd.h> #include <cstdio> #include <flat_set> +#include <future> #include <scn/scan.h> #include <span> #include <sys/utsname.h> @@ -78,7 +79,7 @@ namespace WebStat { const Impl impl; LastRunTime lastRun {LastRunTime::clock::now()}; - std::optional<std::thread> currentRun {std::nullopt}; + std::optional<std::future<unsigned int>> currentRun; }; Job::LastRunTime lastCheckedJobs {Job::LastRunTime::clock::now()}; |
