diff options
| author | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-03-17 11:11:14 +0000 |
|---|---|---|
| committer | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-03-17 11:11:14 +0000 |
| commit | 0e3c2e8dd462a7d56f8b61e15c8cf10681898a1f (patch) | |
| tree | cf1b47683fcbe33d495872d72627f3bccc40cc91 /src/ingestor.hpp | |
| parent | 04acfa679fd846ac829ded5562093b3766c85154 (diff) | |
| download | webstat-0e3c2e8dd462a7d56f8b61e15c8cf10681898a1f.tar.bz2 webstat-0e3c2e8dd462a7d56f8b61e15c8cf10681898a1f.tar.xz webstat-0e3c2e8dd462a7d56f8b61e15c8cf10681898a1f.zip | |
Run jobs on a background thread
Diffstat (limited to 'src/ingestor.hpp')
| -rw-r--r-- | src/ingestor.hpp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/ingestor.hpp b/src/ingestor.hpp index 67a7a15..72417d9 100644 --- a/src/ingestor.hpp +++ b/src/ingestor.hpp @@ -54,7 +54,7 @@ namespace WebStat { void parkLogLine(std::string_view); void runJobsIdle(); - void jobIngestParkedLines(); + unsigned int jobIngestParkedLines(); unsigned int jobPurgeOldLogs(); template<typename... T> void storeLogLine(DB::Connection *, const std::tuple<T...> &) const; @@ -70,9 +70,19 @@ namespace WebStat { size_t linesParked = 0; mutable std::flat_set<Crc32Value> existingEntities; - using JobLastRunTime = std::chrono::system_clock::time_point; - JobLastRunTime lastRunIngestParkedLines; - JobLastRunTime lastRunPurgeOldLogs; + struct Job { + using LastRunTime = std::chrono::system_clock::time_point; + using Impl = unsigned int (Ingestor::*)(); + + explicit Job(Impl impl) : impl(impl) { } + + const Impl impl; + LastRunTime lastRun {LastRunTime::clock::now()}; + std::optional<std::thread> currentRun {std::nullopt}; + }; + + Job ingestParkedLines; + Job purgeOldLogs; private: static constexpr size_t MAX_NEW_ENTITIES = 6; |
