Skip to content

Commit

Permalink
Use lastPoll time as cutoff on subsequent polls
Browse files Browse the repository at this point in the history
  • Loading branch information
tom--pollard committed Apr 27, 2021
1 parent 4d23df3 commit 23dbef8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cmd/scheduled-feed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 23dbef8

Please sign in to comment.