From ed3598ac6f77f62b0c4fe32d4dab05784e5fa51d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 1 May 2026 15:31:02 +0100 Subject: Return a callable from jobs Allows safely running finalisation code in the main thread if required. --- src/ingestor.hpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/ingestor.hpp') diff --git a/src/ingestor.hpp b/src/ingestor.hpp index c57c16a..4882b7d 100644 --- a/src/ingestor.hpp +++ b/src/ingestor.hpp @@ -60,8 +60,20 @@ namespace WebStat { std::expected parkQueuedLogLines(); void runJobsAsNeeded(); - unsigned int jobIngestParkedLines(); - unsigned int jobPurgeOldLogs(); + struct Job { + using LastRunTime = std::chrono::system_clock::time_point; + using Result = std::function; + using Impl = Result (Ingestor::*)(); + + explicit Job(Impl jobImpl) : impl(jobImpl) { } + + const Impl impl; + LastRunTime lastRun {LastRunTime::clock::now()}; + std::optional> currentRun; + }; + + Job::Result jobIngestParkedLines(); + Job::Result jobPurgeOldLogs(); template void storeLogLine(DB::Connection *, const std::tuple &) const; @@ -86,17 +98,6 @@ namespace WebStat { bool terminated = false; - struct Job { - using LastRunTime = std::chrono::system_clock::time_point; - using Impl = unsigned int (Ingestor::*)(); - - explicit Job(Impl jobImpl) : impl(jobImpl) { } - - const Impl impl; - LastRunTime lastRun {LastRunTime::clock::now()}; - std::optional> currentRun; - }; - Job::LastRunTime lastCheckedJobs {Job::LastRunTime::clock::now()}; Job ingestParkedLines; Job purgeOldLogs; -- cgit v1.3