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

Function NewTracker

coderd/workspacestats/tracker.go:46–67  ·  view source on GitHub ↗

NewTracker returns a new Tracker. It is the caller's responsibility to call Close().

(s Store, opts ...TrackerOption)

Source from the content-addressed store, hash-verified

44// NewTracker returns a new Tracker. It is the caller's responsibility
45// to call Close().
46func NewTracker(s Store, opts ...TrackerOption) *UsageTracker {
47 tr := &UsageTracker{
48 log: slog.Make(sloghuman.Sink(os.Stderr)),
49 m: &uuidSet{},
50 s: s,
51 tickCh: nil,
52 stopTick: nil,
53 stopCh: make(chan struct{}),
54 doneCh: make(chan struct{}),
55 flushCh: nil,
56 }
57 for _, opt := range opts {
58 opt(tr)
59 }
60 if tr.tickCh == nil && tr.stopTick == nil {
61 tick := time.NewTicker(DefaultFlushInterval)
62 tr.tickCh = tick.C
63 tr.stopTick = tick.Stop
64 }
65 go tr.loop()
66 return tr
67}
68
69type TrackerOption func(*UsageTracker)
70

Callers 7

NewFunction · 0.92
NewOptionsFunction · 0.92
TestTrackerFunction · 0.92
TestUpdateStatsFunction · 0.92
ServerMethod · 0.92

Calls 1

loopMethod · 0.95

Tested by 4

TestTrackerFunction · 0.74
TestUpdateStatsFunction · 0.74