add logging for things

This commit is contained in:
Andre Medeiros 2022-05-25 19:55:51 -04:00
parent 5ede5d6987
commit 47a0aa47dd
2 changed files with 19 additions and 2 deletions

View file

@ -335,6 +335,17 @@ func (sc *subredditsConsumer) Consume(delivery rmq.Delivery) {
continue continue
} }
sc.logger.Info("matched post",
zap.Int64("subreddit#id", id),
zap.String("subreddit#name", subreddit.NormalizedName()),
zap.Int64("watcher#id", watcher.ID),
zap.String("watcher#keywords", watcher.Keyword),
zap.Int64("watcher#upvotes", watcher.Upvotes),
zap.String("post#id", post.ID),
zap.String("post#title", post.Title),
zap.Int64("post#score", post.Score),
)
lockKey := fmt.Sprintf("watcher:%d:%s", watcher.DeviceID, post.ID) lockKey := fmt.Sprintf("watcher:%d:%s", watcher.DeviceID, post.ID)
notified, _ := sc.redis.Get(sc, lockKey).Bool() notified, _ := sc.redis.Get(sc, lockKey).Bool()

View file

@ -174,7 +174,7 @@ func (tc *trendingConsumer) Consume(delivery rmq.Delivery) {
tps, err := rac.SubredditTop(tc, subreddit.Name, reddit.WithQuery("t", "week")) tps, err := rac.SubredditTop(tc, subreddit.Name, reddit.WithQuery("t", "week"))
if err != nil { if err != nil {
tc.logger.Error("failed to fetch month's top posts", tc.logger.Error("failed to fetch weeks's top posts",
zap.Error(err), zap.Error(err),
zap.Int64("subreddit#id", id), zap.Int64("subreddit#id", id),
zap.String("subreddit#name", subreddit.NormalizedName()), zap.String("subreddit#name", subreddit.NormalizedName()),
@ -182,7 +182,7 @@ func (tc *trendingConsumer) Consume(delivery rmq.Delivery) {
return return
} }
tc.logger.Debug("loaded month's top posts", tc.logger.Debug("loaded weeks's top posts",
zap.Int64("subreddit#id", id), zap.Int64("subreddit#id", id),
zap.String("subreddit#name", subreddit.NormalizedName()), zap.String("subreddit#name", subreddit.NormalizedName()),
zap.Int("count", tps.Count), zap.Int("count", tps.Count),
@ -205,11 +205,17 @@ func (tc *trendingConsumer) Consume(delivery rmq.Delivery) {
return return
} }
posts := make([]string, tps.Count)
for i, post := range tps.Children {
posts[i] = fmt.Sprintf("%s: %d", post.Title, post.Score)
}
middlePost := tps.Count / 2 middlePost := tps.Count / 2
medianScore := tps.Children[middlePost].Score medianScore := tps.Children[middlePost].Score
tc.logger.Info("calculated median score", tc.logger.Info("calculated median score",
zap.Int64("subreddit#id", id), zap.Int64("subreddit#id", id),
zap.String("subreddit#name", subreddit.NormalizedName()), zap.String("subreddit#name", subreddit.NormalizedName()),
zap.Strings("subreddit#posts", posts),
zap.Int64("score", medianScore), zap.Int64("score", medianScore),
) )