From 40cbaadf830c6b6635c6e2649da4ef7fdcceb6f1 Mon Sep 17 00:00:00 2001 From: balki <3070606-balki@users.noreply.gitlab.com> Date: Mon, 23 May 2022 13:56:19 -0400 Subject: [PATCH] add stats to log --- app/app.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/app.go b/app/app.go index 9dd39e8..ff5cff3 100644 --- a/app/app.go +++ b/app/app.go @@ -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 }