Run 阻塞循环 push usage,直到 ctx done。
(ctx context.Context)
| 83 | |
| 84 | // Run 阻塞循环 push usage,直到 ctx done。 |
| 85 | func (p *UsagePusher) Run(ctx context.Context) error { |
| 86 | t := time.NewTicker(p.interval) |
| 87 | defer t.Stop() |
| 88 | |
| 89 | for { |
| 90 | select { |
| 91 | case <-ctx.Done(): |
| 92 | return ctx.Err() |
| 93 | case <-t.C: |
| 94 | p.tick(ctx) |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // Tick 执行单次推送循环。仅供测试 / 集成验证使用:生产路径走 Run。 |
| 100 | func (p *UsagePusher) Tick(ctx context.Context) { p.tick(ctx) } |