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

Function New

coderd/database/dbrollup/dbrollup.go:62–82  ·  view source on GitHub ↗

New creates a new DB rollup service that periodically runs rollup queries. It is the caller's responsibility to call Close on the returned instance. This is for e.g. generating insights data (template_usage_stats) from raw data (workspace_agent_stats, workspace_app_stats).

(logger slog.Logger, db database.Store, opts ...Option)

Source from the content-addressed store, hash-verified

60// This is for e.g. generating insights data (template_usage_stats) from
61// raw data (workspace_agent_stats, workspace_app_stats).
62func New(logger slog.Logger, db database.Store, opts ...Option) *Rolluper {
63 ctx, cancel := context.WithCancel(context.Background())
64
65 r := &Rolluper{
66 cancel: cancel,
67 closed: make(chan struct{}),
68 db: db,
69 logger: logger,
70 interval: DefaultInterval,
71 }
72
73 for _, opt := range opts {
74 opt(r)
75 }
76
77 //nolint:gocritic // The system rolls up database tables without user input.
78 ctx = dbauthz.AsSystemRestricted(ctx)
79 go r.start(ctx)
80
81 return r
82}
83
84func (r *Rolluper) start(ctx context.Context) {
85 defer close(r.closed)

Callers 11

TestDeploymentInsightsFunction · 0.92
TestUserLatencyInsightsFunction · 0.92
NewFunction · 0.92
TestRollup_CloseFunction · 0.92

Calls 2

startMethod · 0.95
AsSystemRestrictedFunction · 0.92