mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-25 13:17:42 +00:00
update last checked at
This commit is contained in:
parent
aad2434d83
commit
f956033e2d
1 changed files with 18 additions and 17 deletions
|
@ -287,28 +287,29 @@ func (c *Consumer) Consume(delivery rmq.Delivery) {
|
||||||
"count": len(msgs.MessageListing.Messages),
|
"count": len(msgs.MessageListing.Messages),
|
||||||
}).Debug("fetched 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 {
|
if len(msgs.MessageListing.Messages) == 0 {
|
||||||
c.logger.WithFields(logrus.Fields{
|
c.logger.WithFields(logrus.Fields{
|
||||||
"accountID": id,
|
"accountID": id,
|
||||||
}).Debug("no new messages, bailing early")
|
}).Debug("no new messages, bailing early")
|
||||||
|
|
||||||
if err = c.pool.BeginFunc(ctx, func(tx pgx.Tx) error {
|
delivery.Ack()
|
||||||
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()
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue