MCPcopy Create free account
hub / github.com/AdRoll/baker / Run

Method Run

input/kcl.go:198–229  ·  view source on GitHub ↗

Run implements baker.Input.

(inch chan<- *baker.Data)

Source from the content-addressed store, hash-verified

196
197// Run implements baker.Input.
198func (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
232func (k *KCL) Stats() baker.InputStats {

Callers

nothing calls this directly

Calls 4

totalShardsMethod · 0.95
StopMethod · 0.65
StartMethod · 0.45
ShutdownMethod · 0.45

Tested by

no test coverage detected