fix queue delay reporting

This commit is contained in:
Andre Medeiros 2021-08-14 14:15:05 -04:00
parent 42a9fb415e
commit 99f76c8cca

View file

@ -171,7 +171,8 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
return
}
newAccount := (account.LastCheckedAt == 0)
previousLastCheckedAt := account.LastCheckedAt
newAccount := (previousLastCheckedAt == 0)
account.LastCheckedAt = now
if err = nc.accountRepo.Update(ctx, &account); err != nil {
@ -228,7 +229,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
// Only update delay on accounts we can actually check, otherwise it skews
// the numbers too much.
if !newAccount {
latency := now - account.LastCheckedAt - float64(backoff)
latency := now - previousLastCheckedAt - float64(backoff)
nc.statsd.Histogram("apollo.queue.delay", latency, []string{}, rate)
}