add stats to log

This commit is contained in:
Balakrishnan Balasubramanian 2022-05-23 13:56:19 -04:00
parent 67e479c865
commit 40cbaadf83

View File

@ -82,9 +82,23 @@ func ProcessFeed(feed *FeedCfg, scheduler Scheduler, dbDir string, tgram telegra
scheduler.Good(feed.Name)
stat := struct {
Total int
New int
Filtered int
Error int
}{}
defer func() {
log.Info("done processing feed", "feed", feed.Name, "total", stat.Total, "new", stat.New, "filtered", stat.Filtered, "error", stat.Error)
}()
stat.Total = len(entries)
var records []Record
var newEntries []parser.FeedEntry
if db.IsNewFeed() {
stat.New = stat.Total
ftl := int(feed.FirstTimeLimit)
if feed.FirstTimeLimit == NoLimit || len(entries) <= ftl {
newEntries = entries
@ -99,12 +113,15 @@ func ProcessFeed(feed *FeedCfg, scheduler Scheduler, dbDir string, tgram telegra
FeedEntry: entry,
})
}
stat.Filtered = len(filteredEntries)
}
} else {
newEntries, err = db.Filter(entries)
if err != nil {
log.Error("failed to filter entries", "feed", feed.Name, "error", err)
return
}
stat.New = len(newEntries)
}
for _, entry := range newEntries {
@ -116,6 +133,7 @@ func ProcessFeed(feed *FeedCfg, scheduler Scheduler, dbDir string, tgram telegra
if err != nil {
log.Error("failed to send to telegram", "feed", feed.Name, "link", entry.Link, "channel", feed.Channel, "rhash", feed.Rhash, "error", err)
r.Status = Error
stat.Error++
} else {
r.Status = Sent
}