296
}
297
298
>
func (db *taskQueueDB) SyncState(ctx context.Context) error {
db.go
299
>
db.Lock()
300
>
defer db.Unlock()
301
>
defer db.emitPhysicalBacklogGaugesLocked()
302
>
303
>
// We only need to write if something changed, or if we're past half of the persistence TTL.
304
>
// Cap at 24h so that the scavenger (which looks for metadata not updated in 48h) doesn't
305
>
// mistake the queue for idle, even if a future partition kind has a longer TTL.
306
>
ttl := min(24*time.Hour, cmp.Or(db.queue.Partition().PersistenceTTL(), 24*time.Hour))
307
>
needWrite := db.lastChange.After(db.lastWrite) || time.Since(db.lastWrite) > ttl/2
308
>
if !needWrite {
309
// If we don't write, though, we wouldn't know if someone else has stolen ownership
310
// momentarily (this could happen due to eventual consistency of membership updates).