mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-22 03:37:43 +00:00
fix edge cases
This commit is contained in:
parent
b07bf599de
commit
b5bc51dfd7
2 changed files with 18 additions and 8 deletions
|
@ -280,11 +280,9 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
|
|||
"count": msgs.Count,
|
||||
}).Debug("fetched messages")
|
||||
|
||||
for i := msgs.Count - 1; i >= 0; i-- {
|
||||
msg := msgs.Children[i]
|
||||
|
||||
for _, msg := range msgs.Children {
|
||||
if !msg.IsDeleted() {
|
||||
account.LastMessageID = msgs.Children[0].FullName()
|
||||
account.LastMessageID = msg.FullName()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,6 +173,8 @@ func (snc *stuckNotificationsConsumer) Consume(delivery rmq.Delivery) {
|
|||
continue
|
||||
}
|
||||
|
||||
lastAlertedAt = thing.CreatedAt
|
||||
|
||||
if !thing.IsDeleted() {
|
||||
snc.logger.WithFields(logrus.Fields{
|
||||
"account#username": account.NormalizedUsername(),
|
||||
|
@ -180,8 +182,6 @@ func (snc *stuckNotificationsConsumer) Consume(delivery rmq.Delivery) {
|
|||
}).Debug("thing exists, returning")
|
||||
return
|
||||
}
|
||||
|
||||
lastAlertedAt = thing.CreatedAt
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,13 +203,25 @@ func (snc *stuckNotificationsConsumer) Consume(delivery rmq.Delivery) {
|
|||
|
||||
account.LastMessageID = ""
|
||||
for _, thing := range things.Children {
|
||||
if lastAlertedAt > thing.CreatedAt && !thing.IsDeleted() {
|
||||
if thing.IsDeleted() {
|
||||
continue
|
||||
}
|
||||
|
||||
if lastAlertedAt == 0 {
|
||||
account.LastMessageID = thing.FullName()
|
||||
break
|
||||
}
|
||||
|
||||
account.LastMessageID = thing.FullName()
|
||||
if lastAlertedAt > thing.CreatedAt {
|
||||
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 {
|
||||
snc.logger.WithFields(logrus.Fields{
|
||||
"account#username": account.NormalizedUsername(),
|
||||
|
|
Loading…
Reference in a new issue