fix edge cases

This commit is contained in:
Andre Medeiros 2021-10-17 11:27:52 -04:00
parent b07bf599de
commit b5bc51dfd7
2 changed files with 18 additions and 8 deletions

View file

@ -280,11 +280,9 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
"count": msgs.Count, "count": msgs.Count,
}).Debug("fetched messages") }).Debug("fetched messages")
for i := msgs.Count - 1; i >= 0; i-- { for _, msg := range msgs.Children {
msg := msgs.Children[i]
if !msg.IsDeleted() { if !msg.IsDeleted() {
account.LastMessageID = msgs.Children[0].FullName() account.LastMessageID = msg.FullName()
break break
} }
} }

View file

@ -173,6 +173,8 @@ func (snc *stuckNotificationsConsumer) Consume(delivery rmq.Delivery) {
continue continue
} }
lastAlertedAt = thing.CreatedAt
if !thing.IsDeleted() { if !thing.IsDeleted() {
snc.logger.WithFields(logrus.Fields{ snc.logger.WithFields(logrus.Fields{
"account#username": account.NormalizedUsername(), "account#username": account.NormalizedUsername(),
@ -180,8 +182,6 @@ func (snc *stuckNotificationsConsumer) Consume(delivery rmq.Delivery) {
}).Debug("thing exists, returning") }).Debug("thing exists, returning")
return return
} }
lastAlertedAt = thing.CreatedAt
} }
} }
@ -203,12 +203,24 @@ func (snc *stuckNotificationsConsumer) Consume(delivery rmq.Delivery) {
account.LastMessageID = "" account.LastMessageID = ""
for _, thing := range things.Children { for _, thing := range things.Children {
if lastAlertedAt > thing.CreatedAt && !thing.IsDeleted() { if thing.IsDeleted() {
continue
}
if lastAlertedAt == 0 {
account.LastMessageID = thing.FullName()
break break
} }
if lastAlertedAt > thing.CreatedAt {
account.LastMessageID = thing.FullName() account.LastMessageID = thing.FullName()
} }
}
snc.logger.WithFields(logrus.Fields{
"account#username": account.NormalizedUsername(),
"thing#id": account.LastMessageID,
}).Debug("updating last good thing")
if err := snc.accountRepo.Update(ctx, &account); err != nil { if err := snc.accountRepo.Update(ctx, &account); err != nil {
snc.logger.WithFields(logrus.Fields{ snc.logger.WithFields(logrus.Fields{