MCPcopy Create free account
hub / github.com/coder/coder / Start

Method Start

enterprise/coderd/usage/publisher.go:126–156  ·  view source on GitHub ↗

Start implements Publisher.

()

Source from the content-addressed store, hash-verified

124
125// Start implements Publisher.
126func (p *tallymanPublisher) Start() error {
127 ctx := p.ctx
128 deploymentID, err := p.db.GetDeploymentID(ctx)
129 if err != nil {
130 return xerrors.Errorf("get deployment ID: %w", err)
131 }
132 deploymentUUID, err := uuid.Parse(deploymentID)
133 if err != nil {
134 return xerrors.Errorf("parse deployment ID %q: %w", deploymentID, err)
135 }
136
137 if p.initialDelay <= 0 {
138 // Pick a random time between tallymanPublishInitialMinimumDelay and
139 // tallymanPublishInterval.
140 maxPlusDelay := tallymanPublishInterval - tallymanPublishInitialMinimumDelay
141 plusDelay, err := cryptorand.Int63n(int64(maxPlusDelay))
142 if err != nil {
143 return xerrors.Errorf("could not generate random start delay: %w", err)
144 }
145 p.initialDelay = tallymanPublishInitialMinimumDelay + time.Duration(plusDelay)
146 }
147
148 if len(p.licenseKeys) == 0 {
149 return xerrors.New("no license keys provided")
150 }
151
152 pproflabel.Go(ctx, pproflabel.Service(pproflabel.ServiceTallymanPublisher), func(ctx context.Context) {
153 p.publishLoop(ctx, deploymentUUID)
154 })
155 return nil
156}
157
158func (p *tallymanPublisher) publishLoop(ctx context.Context, deploymentID uuid.UUID) {
159 defer close(p.done)

Callers

nothing calls this directly

Calls 9

publishLoopMethod · 0.95
Int63nFunction · 0.92
GoFunction · 0.92
ServiceFunction · 0.92
DurationMethod · 0.80
GetDeploymentIDMethod · 0.65
ParseMethod · 0.65
NewMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected