Skip to content

Commit

Permalink
scheduled-feed: cron request directly to poll/publish funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
tom--pollard committed May 6, 2021
1 parent d1bfd8c commit 26d0b4d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions cmd/scheduled-feed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func main() {
cronjob := cron.New()
crontab := fmt.Sprintf("@every %s", pollRate.String())
log.Printf("Running a timer %s", crontab)
err := cronjob.AddFunc(crontab, func() { cronRequest(appConfig.HTTPPort) })
err := cronjob.AddFunc(crontab, func() { cronPoll(handler) })
if err != nil {
log.Fatal(err)
}
Expand All @@ -147,14 +147,16 @@ func main() {
}
}

func cronRequest(port int) {
client := &http.Client{
Timeout: 10 * time.Second,
}
resp, err := client.Get(fmt.Sprintf("http://localhost:%v", port))
func cronPoll(handler *FeedHandler) {
pkgs, pollErrors := handler.pollFeeds()
processedPackages, err := handler.publishPackages(pkgs)
if err != nil {
log.Printf("http request failed: %v", err)
log.Errorf(err.Error())
return
}
if pollErrors {
// pollFeeds already logs with ErrorF.
return
}
resp.Body.Close()
log.Printf("%d packages processed", processedPackages)
}

0 comments on commit 26d0b4d

Please sign in to comment.