From 23dbef822685c9e95e1a94e8229cfb966fa111cd Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Mon, 26 Apr 2021 12:18:07 +0100 Subject: [PATCH] Use lastPoll time as cutoff on subsequent polls --- cmd/scheduled-feed/main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/scheduled-feed/main.go b/cmd/scheduled-feed/main.go index 70d23918..9462b98f 100644 --- a/cmd/scheduled-feed/main.go +++ b/cmd/scheduled-feed/main.go @@ -22,10 +22,12 @@ type FeedHandler struct { scheduler *scheduler.Scheduler pub publisher.Publisher delta time.Duration + lastPoll time.Time } func (handler *FeedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - cutoff := time.Now().UTC().Add(-handler.delta) + cutoff := handler.getCutoff() + handler.lastPoll = time.Now().UTC() pkgs, errs := handler.scheduler.Poll(cutoff) if len(errs) > 0 { for _, err := range errs { @@ -59,6 +61,16 @@ func (handler *FeedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Write([]byte(fmt.Sprintf("%d packages processed", processed))) } +func (handler FeedHandler) getCutoff() time.Time { + var cutoff time.Time + if handler.lastPoll.IsZero() { + cutoff = time.Now().UTC().Add(-handler.delta) + } else { + cutoff = handler.lastPoll + } + return cutoff +} + func main() { configPath, useConfig := os.LookupEnv("PACKAGE_FEEDS_CONFIG_PATH") var err error