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/util.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/util.hpp') diff --git a/src/util.hpp b/src/util.hpp index 8f2a585..28bcebd 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -75,4 +75,24 @@ namespace WebStat { return out; } + + template + bool + expired(const std::chrono::time_point lastRun, const std::chrono::duration freq, + const typename Clock::time_point now = Clock::now()) + { + return lastRun + freq < now; + } + + template + bool + expiredThenSet(std::chrono::time_point & lastRun, const std::chrono::duration freq, + const typename Clock::time_point now = Clock::now()) + { + if (expired(lastRun, freq, now)) { + lastRun = now; + return true; + } + return false; + } } -- cgit v1.3