From 7e9358c89917420723c2a113f708b2e034c0562d Mon Sep 17 00:00:00 2001 From: Tom Pollard Date: Thu, 29 Apr 2021 13:47:41 +0100 Subject: [PATCH] scheduled-feed: cron request directly to poll/publish funcs --- cmd/scheduled-feed/main.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/scheduled-feed/main.go b/cmd/scheduled-feed/main.go index 5d6d851c..4d262943 100644 --- a/cmd/scheduled-feed/main.go +++ b/cmd/scheduled-feed/main.go @@ -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) } @@ -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) }