| 156 | } |
| 157 | |
| 158 | func (p *tallymanPublisher) publishLoop(ctx context.Context, deploymentID uuid.UUID) { |
| 159 | defer close(p.done) |
| 160 | |
| 161 | // Start the ticker with the initial delay. We will reset it to the interval |
| 162 | // after the first tick. |
| 163 | ticker := p.clock.NewTicker(p.initialDelay) |
| 164 | defer ticker.Stop() |
| 165 | |
| 166 | for { |
| 167 | select { |
| 168 | case <-ctx.Done(): |
| 169 | return |
| 170 | case <-ticker.C: |
| 171 | } |
| 172 | |
| 173 | err := p.publish(ctx, deploymentID) |
| 174 | if err != nil { |
| 175 | p.log.Warn(ctx, "publish usage events to tallyman", slog.Error(err)) |
| 176 | } |
| 177 | ticker.Reset(tallymanPublishInterval) |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | // publish publishes usage events to Tallyman in a loop until there is an error |
| 182 | // (or any rejection) or there are no more events to publish. |