Debian Codegraph @

runutil/runutil.go

raw symbols SCIP
1 // Copyright (c) The EfficientGo Authors.
2 // Licensed under the Apache License 2.0.
3
4 // Initially copied from Thanos
5 //
6 // Copyright (c) The Thanos Authors.
7 // Licensed under the Apache License 2.0.
8
9 package runutilscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/runutil`/
10
11 import (
12 "timescip-go gomod github.com/golang/go/src go1.17 time/"
13 )
14
15 // Repeat executes f every interval seconds until stopc is closed or f returns an error.
16 // It executes f once right after being called.
17 func Repeatscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/runutil`/Repeat().(interval timescip-go gomod github.com/golang/go/src go1.17 time/.Durationscip-go gomod github.com/golang/go/src go1.17 time/Duration#, stopc <-chan struct{}, f func() error) error {
18 tick := timescip-go gomod github.com/golang/go/src go1.17 time/.NewTickerscip-go gomod github.com/golang/go/src go1.17 time/NewTicker().(interval)
19 defer tick.Stopscip-go gomod github.com/golang/go/src go1.17 time/Ticker#Stop().()
20
21 for {
22 if err := f(); err != nil {
23 return err
24 }
25 select {
26 case <-stopc:
27 return nil
28 case <-tick.Cscip-go gomod github.com/golang/go/src go1.17 time/Ticker#C.:
29 }
30 }
31 }
32
33 // Logger interface compatible with go-kit/logger.
34 type Loggerscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/runutil`/Logger# interface {
35 Logscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/runutil`/Logger#Log.(keyvals ...interface{}) error
36 }
37
38 // Retry executes f every interval seconds until timeout or no error is returned from f.
39 func Retryscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/runutil`/Retry().(interval timescip-go gomod github.com/golang/go/src go1.17 time/.Durationscip-go gomod github.com/golang/go/src go1.17 time/Duration#, stopc <-chan struct{}, f func() error) error {
40 return RetryWithLogscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/runutil`/RetryWithLog().(nil, interval, stopc, f)
41 }
42
43 // RetryWithLog executes f every interval seconds until timeout or no error is returned from f. It logs an error on each f error.
44 func RetryWithLogscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/runutil`/RetryWithLog().(logger Loggerscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/runutil`/Logger#, interval timescip-go gomod github.com/golang/go/src go1.17 time/.Durationscip-go gomod github.com/golang/go/src go1.17 time/Duration#, stopc <-chan struct{}, f func() error) error {
45 tick := timescip-go gomod github.com/golang/go/src go1.17 time/.NewTickerscip-go gomod github.com/golang/go/src go1.17 time/NewTicker().(interval)
46 defer tick.Stopscip-go gomod github.com/golang/go/src go1.17 time/Ticker#Stop().()
47
48 var err error
49 for {
50 if err = f(); err == nil {
51 return nil
52 }
53 if logger != nil {
54 _ = logger.Logscip-go gomod github.com/efficientgo/core . `github.com/efficientgo/core/runutil`/Logger#Log.("msg", "function failed. Retrying in next tick", "err", err)
55 }
56 select {
57 case <-stopc:
58 return err
59 case <-tick.Cscip-go gomod github.com/golang/go/src go1.17 time/Ticker#C.:
60 }
61 }
62 }