File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -348,27 +348,31 @@ func (sc *StatsCollector) start() {
348
348
}()
349
349
sc .opts .Logger .Info (sc .ctx , "workspace app stats collector started" )
350
350
351
- ticker := time .NewTicker (sc .opts .ReportInterval )
352
- defer ticker .Stop ()
351
+ t := time .NewTimer (sc .opts .ReportInterval )
352
+ defer t .Stop ()
353
353
354
354
var reportFlushDone chan <- struct {}
355
355
done := false
356
356
for ! done {
357
357
select {
358
358
case <- sc .ctx .Done ():
359
- ticker .Stop ()
359
+ t .Stop ()
360
360
done = true
361
- case <- ticker .C :
361
+ case <- t .C :
362
362
case reportFlushDone = <- sc .opts .Flush :
363
363
}
364
364
365
365
// Ensure we don't hold up this request for too long. Add a few
366
366
// seconds to prevent very short intervals from causing a timeout.
367
- ctx , cancel := context .WithTimeout (context .Background (), sc . opts . ReportInterval + 5 * time .Second )
367
+ ctx , cancel := context .WithTimeout (context .Background (), 15 * time .Second )
368
368
//nolint:gocritic // Inserting app stats is a system function.
369
369
_ = sc .flush (dbauthz .AsSystemRestricted (ctx ))
370
370
cancel ()
371
371
372
+ if ! done {
373
+ t .Reset (sc .opts .ReportInterval )
374
+ }
375
+
372
376
// For tests.
373
377
if reportFlushDone != nil {
374
378
reportFlushDone <- struct {}{}
You can’t perform that action at this time.
0 commit comments