MCPcopy
hub / github.com/grafana/tempo / job

Function job

modules/generator/registry/job.go:9–29  ·  modules/generator/registry/job.go::job

job executes f every getInterval.

(ctx context.Context, f func(context.Context), getInterval func() time.Duration)

Source from the content-addressed store, hash-verified

7
8// job executes f every getInterval.
9func job(ctx context.Context, f func(context.Context), getInterval func() time.Duration) {
10 currentInterval := getInterval()
11 ticker := time.NewTicker(currentInterval)
12
13 for {
14 select {
15 case <-ctx.Done():
16 return
17 case <-ticker.C:
18 jobCtx, cancel := context.WithTimeout(ctx, currentInterval)
19 f(jobCtx)
20 cancel()
21 }
22
23 newInterval := getInterval()
24 if currentInterval != newInterval {
25 ticker = time.NewTicker(newInterval)
26 currentInterval = newInterval
27 }
28 }
29}
30
31func constantInterval(interval time.Duration) func() time.Duration {
32 return func() time.Duration {

Callers 2

NewFunction · 0.70
Test_jobFunction · 0.70

Calls 2

fFunction · 0.85
DoneMethod · 0.65

Tested by 1

Test_jobFunction · 0.56