From aa87dca0902dfb1cfb6187573fda4b3f2aa8ad99 Mon Sep 17 00:00:00 2001 From: AKP Date: Wed, 6 Apr 2022 15:23:52 +0100 Subject: Fix worker scheduling issues once and for all (I hope??) Signed-off-by: AKP --- walrss/internal/rss/watcher.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/walrss/internal/rss/watcher.go b/walrss/internal/rss/watcher.go index 502b4c1..c29cb69 100644 --- a/walrss/internal/rss/watcher.go +++ b/walrss/internal/rss/watcher.go @@ -10,13 +10,21 @@ import ( func StartWatcher(st *state.State) { go func() { currentTime := time.Now().UTC() - time.Sleep(time.Minute * time.Duration(60-currentTime.Minute())) + + timeUntilNextHour := time.Minute * time.Duration(60 - currentTime.Minute()) + timeUntilNextHour += 30 * time.Second // little bit of buffer time to + // make sure we're actually going to be within in the new hour + + time.Sleep(timeUntilNextHour) runFeedProcessor(st, currentTime) ticker := time.NewTicker(time.Hour) - for currentTime := range ticker.C { - runFeedProcessor(st, currentTime) + for range ticker.C { + // Yes, I am aware that you can get the current time from ticker.C + // BUT that's been weird and caused some issues resulting in an + // hour's task not being run, so I'm not using it + runFeedProcessor(st, time.Now().UTC()) } }() } -- cgit v1.2.3-70-g09d2