diff options
| author | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-03-17 11:48:34 +0000 |
|---|---|---|
| committer | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-03-17 11:48:34 +0000 |
| commit | d2ecb7f49c3f3b60e3d1f297fd033071a02cfa9a (patch) | |
| tree | 90c34529461f86f2b6f59ba44f9d910214ed8630 /src/util.hpp | |
| parent | 0e3c2e8dd462a7d56f8b61e15c8cf10681898a1f (diff) | |
| download | webstat-d2ecb7f49c3f3b60e3d1f297fd033071a02cfa9a.tar.bz2 webstat-d2ecb7f49c3f3b60e3d1f297fd033071a02cfa9a.tar.xz webstat-d2ecb7f49c3f3b60e3d1f297fd033071a02cfa9a.zip | |
Execute jobs even when processing incoming logs
Jobs run on background threads now, so we can happily run them even when
we're busy.
Diffstat (limited to 'src/util.hpp')
| -rw-r--r-- | src/util.hpp | 20 |
1 files changed, 20 insertions, 0 deletions
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<typename Clock, typename Dur, typename Rep, typename Period> + bool + expired(const std::chrono::time_point<Clock, Dur> lastRun, const std::chrono::duration<Rep, Period> freq, + const typename Clock::time_point now = Clock::now()) + { + return lastRun + freq < now; + } + + template<typename Clock, typename Dur, typename Rep, typename Period> + bool + expiredThenSet(std::chrono::time_point<Clock, Dur> & lastRun, const std::chrono::duration<Rep, Period> freq, + const typename Clock::time_point now = Clock::now()) + { + if (expired(lastRun, freq, now)) { + lastRun = now; + return true; + } + return false; + } } |
