MCPcopy Index your code
hub / github.com/coder/coder / start

Method start

coderd/workspaceapps/stats.go:288–324  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

286}
287
288func (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}

Callers 1

NewStatsCollectorFunction · 0.95

Calls 5

flushMethod · 0.95
AsSystemRestrictedFunction · 0.92
StopMethod · 0.65
ResetMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected