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 Apr 30, 2021
1 parent 7be9b1c commit 7e9358c
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 @@ -130,7 +130,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() { cronRequest(handler) })
if err != nil {
log.Fatal(err)
}
Expand All @@ -143,14 +143,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 cronRequest(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 7e9358c

Please sign in to comment.