aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-23 23:48:09 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2020-04-23 23:48:09 +0200
commit8467dbb9bd9960191f16def3ba43dcbde0fdda14 (patch)
tree5af73797e16dfee0a49de72e122c570053988e51
parent6911562cf4214531343b7509afe77e38b28a0801 (diff)
downloadfeed2imap-go-8467dbb9bd9960191f16def3ba43dcbde0fdda14.tar.gz
feed2imap-go-8467dbb9bd9960191f16def3ba43dcbde0fdda14.tar.bz2
feed2imap-go-8467dbb9bd9960191f16def3ba43dcbde0fdda14.zip
Notify about the number of successfully fetched feeds.
-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 {
ui-shared.h?h=v0.9&id=87a89aed41136d388537b146000c4af6c1135a8c&follow=1'>add cgit_httpscheme() -> http:// or https://Diego Ongaro2-0/+12 2009-06-07Return http statuscode 404 on unknown branchLars Hjemli3-0/+6 2009-06-07Add head-include configuration option.Mark Lodato3-1/+6 2009-03-15CGIT 0.8.2.1v0.8.2.1Lars Hjemli1-1/+1 2009-03-15Fix doc-related glitches in Makefile and .gitignoreLars Hjemli2-1/+6 2009-03-15ui-snapshot: avoid segfault when no filename is specifiedLars Hjemli1-6/+17 2009-03-15fix segfault when displaying empty blobsEric Wong1-5/+8 2009-02-19Add support for HEAD requestsLars Hjemli2-0/+7 2009-02-19Add support for ETag in 'plain' viewLars Hjemli4-0/+5 2009-02-12ui-tree: escape ascii-text properly in hexdump viewLars Hjemli1-4/+9 2009-02-12Makefile: add doc-related targetsLars Hjemli1-2/+17