From f956033e2d1ee3e1d6c5d371888aeeba34afe651 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Thu, 8 Jul 2021 20:33:35 -0400 Subject: [PATCH] update last checked at --- cmd/apollo-worker-notifications/main.go | 35 +++++++++++++------------ 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/cmd/apollo-worker-notifications/main.go b/cmd/apollo-worker-notifications/main.go index b34d8a8..3b0b88d 100644 --- a/cmd/apollo-worker-notifications/main.go +++ b/cmd/apollo-worker-notifications/main.go @@ -287,28 +287,29 @@ func (c *Consumer) Consume(delivery rmq.Delivery) { "count": len(msgs.MessageListing.Messages), }).Debug("fetched messages") + if err = c.pool.BeginFunc(ctx, func(tx pgx.Tx) error { + stmt := ` + UPDATE accounts + SET last_checked_at = $1 + WHERE id = $2` + _, err := tx.Exec(ctx, stmt, now, account.ID) + return err + }); err != nil { + c.logger.WithFields(logrus.Fields{ + "accountID": id, + "err": err, + }).Error("failed to update last_checked_at for account") + + delivery.Reject() + return + } + if len(msgs.MessageListing.Messages) == 0 { c.logger.WithFields(logrus.Fields{ "accountID": id, }).Debug("no new messages, bailing early") - if err = c.pool.BeginFunc(ctx, func(tx pgx.Tx) error { - stmt := ` - UPDATE accounts - SET last_checked_at = $1 - WHERE id = $2` - _, err := tx.Exec(ctx, stmt, now, account.ID) - return err - }); err != nil { - c.logger.WithFields(logrus.Fields{ - "accountID": id, - "err": err, - }).Error("failed to update last_checked_at for account") - - delivery.Reject() - } else { - delivery.Ack() - } + delivery.Ack() return }