Start implements Publisher.
()
| 124 | |
| 125 | // Start implements Publisher. |
| 126 | func (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 | |
| 158 | func (p *tallymanPublisher) publishLoop(ctx context.Context, deploymentID uuid.UUID) { |
| 159 | defer close(p.done) |
nothing calls this directly
no test coverage detected