Run implements baker.Input.
(inch chan<- *baker.Data)
| 196 | |
| 197 | // Run implements baker.Input. |
| 198 | func (k *KCL) Run(inch chan<- *baker.Data) error { |
| 199 | k.inch = inch |
| 200 | |
| 201 | wk := worker.NewWorker(k, k.workerCfg) |
| 202 | if err := wk.Start(); err != nil { |
| 203 | return fmt.Errorf("input: kcl: can't start the worker with: %v", err) |
| 204 | } |
| 205 | defer wk.Shutdown() |
| 206 | |
| 207 | ticker := time.NewTicker(60 * time.Second) |
| 208 | defer ticker.Stop() |
| 209 | // Run a loop that periodically checks the number of shards available in the stream, |
| 210 | // quitting baker as soon as the number changes |
| 211 | for { |
| 212 | select { |
| 213 | case <-k.done: |
| 214 | return nil |
| 215 | case <-ticker.C: |
| 216 | log.Debug("Refreshing shards number") |
| 217 | n, err := k.totalShards() |
| 218 | if err != nil { |
| 219 | log.Errorf("Error refreshing the shards number: %v", err) |
| 220 | continue |
| 221 | } |
| 222 | log.Debugf("Total shards: %d, new shards count: %d", k.streamShards, n) |
| 223 | if k.streamShards != n { |
| 224 | log.Info("Shard number has changed, shutting down") |
| 225 | return nil |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | // Stats implements baker.Input |
| 232 | func (k *KCL) Stats() baker.InputStats { |
nothing calls this directly
no test coverage detected