summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/feed/parse.go24
-rw-r--r--main.go4
2 files changed, 22 insertions, 6 deletions
diff --git a/internal/feed/parse.go b/internal/feed/parse.go
index 22d16f2..35a7596 100644
--- a/internal/feed/parse.go
+++ b/internal/feed/parse.go
@@ -32,22 +32,36 @@ func parseFeed(feed *Feed) error {
return nil
}
-func handleFeed(feed *Feed, wg *sync.WaitGroup) {
- defer wg.Done()
+func handleFeed(feed *Feed, group *sync.WaitGroup, success chan<- bool) {
+ defer group.Done()
log.Printf("Fetching %s from %s", feed.Name, feed.Url)
- if err := parseFeed(feed); err != nil {
+ err := parseFeed(feed)
+ if err != nil {
log.Error(err)
}
+ success <- err == nil
}
-func Parse(feeds Feeds) {
+func Parse(feeds Feeds) int {
var wg sync.WaitGroup
wg.Add(len(feeds))
+ success := make(chan bool, len(feeds))
+
for _, feed := range feeds {
- go handleFeed(feed, &wg)
+ go handleFeed(feed, &wg, success)
}
wg.Wait()
+ close(success)
+
+ ctr := 0
+ for s := range success {
+ if s {
+ ctr++
+ }
+ }
+
+ return ctr
}
diff --git a/main.go b/main.go
index 5764ae4..de59f18 100644
--- a/main.go
+++ b/main.go
@@ -60,7 +60,9 @@ func run() error {
return fmt.Errorf("Configuration invalid: %w", err)
}
- feed.Parse(feeds)
+ if success := feed.Parse(feeds); success == 0 {
+ return fmt.Errorf("No successfull feed fetch.")
+ }
imapUrl, err := url.Parse(cfg.Target)
if err != nil {