MCPcopy Create free account
hub / github.com/cortexproject/cortex / NewTimerService

Function NewTimerService

pkg/util/services/services.go:25–45  ·  view source on GitHub ↗

NewTimerService runs iteration function on every interval tick. When iteration returns error, service fails.

(interval time.Duration, start StartingFn, iter OneIteration, stop StoppingFn)

Source from the content-addressed store, hash-verified

23
24// NewTimerService runs iteration function on every interval tick. When iteration returns error, service fails.
25func NewTimerService(interval time.Duration, start StartingFn, iter OneIteration, stop StoppingFn) *BasicService {
26 run := func(ctx context.Context) error {
27 t := time.NewTicker(interval)
28 defer t.Stop()
29
30 for {
31 select {
32 case <-t.C:
33 err := iter(ctx)
34 if err != nil {
35 return err
36 }
37
38 case <-ctx.Done():
39 return nil
40 }
41 }
42 }
43
44 return NewBasicService(start, run, stop)
45}
46
47// NewListener provides a simple way to build service listener from supplied functions.
48// Functions are only called when not nil.

Callers 10

NewPoolFunction · 0.92
NewRequestQueueFunction · 0.92
newStatePersisterFunction · 0.92
NewLoaderFunction · 0.92
startingMethod · 0.92
TestTimerServiceFunction · 0.85

Calls 3

NewBasicServiceFunction · 0.85
DoneMethod · 0.80
StopMethod · 0.65

Tested by 1

TestTimerServiceFunction · 0.68