()
| 286 | } |
| 287 | |
| 288 | func (sc *StatsCollector) start() { |
| 289 | defer func() { |
| 290 | close(sc.done) |
| 291 | sc.opts.Logger.Debug(sc.ctx, "workspace app stats collector stopped") |
| 292 | }() |
| 293 | sc.opts.Logger.Debug(sc.ctx, "workspace app stats collector started") |
| 294 | |
| 295 | t := time.NewTimer(sc.opts.ReportInterval) |
| 296 | defer t.Stop() |
| 297 | |
| 298 | var reportFlushDone chan<- struct{} |
| 299 | done := false |
| 300 | for !done { |
| 301 | select { |
| 302 | case <-sc.ctx.Done(): |
| 303 | t.Stop() |
| 304 | done = true |
| 305 | case <-t.C: |
| 306 | case reportFlushDone = <-sc.opts.Flush: |
| 307 | } |
| 308 | |
| 309 | ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) |
| 310 | //nolint:gocritic // Inserting app stats is a system function. |
| 311 | _ = sc.flush(dbauthz.AsSystemRestricted(ctx)) |
| 312 | cancel() |
| 313 | |
| 314 | if !done { |
| 315 | t.Reset(sc.opts.ReportInterval) |
| 316 | } |
| 317 | |
| 318 | // For tests. |
| 319 | if reportFlushDone != nil { |
| 320 | reportFlushDone <- struct{}{} |
| 321 | reportFlushDone = nil |
| 322 | } |
| 323 | } |
| 324 | } |
no test coverage detected