Run blocks until ctx is cancelled. Each tick pings all enabled servers, pushes the batch, and (on success) drains up to DrainPerTick spooled batches in age order. On push failure the batch is written to the spool so it survives restarts.
(ctx context.Context)
| 24 | // batches in age order. On push failure the batch is written to the spool |
| 25 | // so it survives restarts. |
| 26 | func (p *Producer) Run(ctx context.Context) { |
| 27 | if existing, err := p.Spool.List(); err == nil && len(existing) > 0 { |
| 28 | log.Warn("spool contains batches from previous run", "count", len(existing)) |
| 29 | } |
| 30 | |
| 31 | ticker := time.NewTicker(p.Interval) |
| 32 | defer ticker.Stop() |
| 33 | |
| 34 | p.tick(ctx) |
| 35 | for { |
| 36 | select { |
| 37 | case <-ctx.Done(): |
| 38 | return |
| 39 | case <-ticker.C: |
| 40 | p.tick(ctx) |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | func (p *Producer) tick(ctx context.Context) { |
| 46 | results := ping.QueryAll(p.Store.Snapshot()) |