@@ -36,13 +36,13 @@ func (p *service) backupTimelockStateWorker(serviceCtx context.Context, state ti
3636 log .Debug ("worker stopped" )
3737 }()
3838
39- delay := 0 * time .Second // Initially no delay, so we can run right after a deploy
39+ start := time .Now ()
4040 cursor := query .EmptyCursor
41- oldestRecordTs := time .Now ()
41+ delay := 0 * time .Second // Initially no delay, so we can run right after a deploy
4242 for {
4343 select {
4444 case <- time .After (delay ):
45- start := time .Now ()
45+ batchStart := time .Now ()
4646
4747 func () {
4848 nr := serviceCtx .Value (metrics .NewRelicContextKey ).(* newrelic.Application )
@@ -59,14 +59,14 @@ func (p *service) backupTimelockStateWorker(serviceCtx context.Context, state ti
5959 )
6060 if err == timelock .ErrTimelockNotFound {
6161 p .metricStatusLock .Lock ()
62- copiedTs := oldestRecordTs
63- if p .oldestTimelockRecord == nil || p . oldestTimelockRecord . After ( copiedTs ) {
64- p .oldestTimelockRecord = & copiedTs
62+ duration := time . Since ( start )
63+ if p .backupTimelockStateWorkerDuration == nil || * p . backupTimelockStateWorkerDuration < duration {
64+ p .backupTimelockStateWorkerDuration = & duration
6565 }
6666 p .metricStatusLock .Unlock ()
6767
68+ start = time .Now ()
6869 cursor = query .EmptyCursor
69- oldestRecordTs = time .Now ()
7070 return
7171 } else if err != nil {
7272 log .WithError (err ).Warn ("failed to get timelock records" )
@@ -77,10 +77,6 @@ func (p *service) backupTimelockStateWorker(serviceCtx context.Context, state ti
7777 for _ , timelockRecord := range timelockRecords {
7878 wg .Add (1 )
7979
80- if timelockRecord .LastUpdatedAt .Before (oldestRecordTs ) {
81- oldestRecordTs = timelockRecord .LastUpdatedAt
82- }
83-
8480 go func (timelockRecord * timelock.Record ) {
8581 defer wg .Done ()
8682
@@ -98,7 +94,7 @@ func (p *service) backupTimelockStateWorker(serviceCtx context.Context, state ti
9894 cursor = query .ToCursor (timelockRecords [len (timelockRecords )- 1 ].Id )
9995 }()
10096
101- delay = interval - time .Since (start )
97+ delay = interval - time .Since (batchStart )
10298 case <- serviceCtx .Done ():
10399 return serviceCtx .Err ()
104100 }
0 commit comments