1818)
1919
2020type Provider struct {
21- ProviderName string
21+ EndpointName string
2222 Name string `yaml:"name"`
2323 Http string `yaml:"http"`
2424 Ws string `yaml:"ws"`
@@ -44,48 +44,48 @@ func (e *Provider) GetTimeout() time.Duration {
4444 return 10 * time .Second
4545}
4646
47- func backoff (attempt int ) time.Duration {
48- backoff := attempt
49- if backoff > 12 {
50- backoff = 12
47+ const highestBackoff = 4 * time .Minute
48+
49+ func nextAttemptDelay (attempt int ) time.Duration {
50+ switch {
51+ case attempt < 5 :
52+ return 10 * time .Second
53+ case attempt < 10 :
54+ return 30 * time .Second
55+ default :
56+ return 1 * time .Minute
5157 }
52- return time .Duration (backoff ) * 10 * time .Second
5358}
5459
55- func (e * Provider ) SetStatus (online bool , err error ) {
56- e .m .Lock ()
57- defer e .m .Unlock ()
60+ func (p * Provider ) SetStatus (online bool , err error ) {
61+ p .m .Lock ()
62+ defer p .m .Unlock ()
5863
59- log := slog .With ("provider" , e . ProviderName , "endpoint" , e .Name )
64+ log := slog .With ("provider" , p . EndpointName , "endpoint" , p .Name )
6065
61- if e .online == online {
66+ if p .online == online {
6267 if ! online {
63- e .attempt ++
64-
65- // Simple backoff
66- if e .retryAt .IsZero () {
67- e .retryAt = time .Now ()
68- }
68+ p .attempt ++
6969
70- e .retryAt = e .retryAt .Add (backoff (e .attempt ))
70+ backoff := nextAttemptDelay (p .attempt )
71+ p .retryAt = time .Now ().Add (backoff )
7172
72- diff := time .Until (e .retryAt )
73- log .Info ("endpoint still offline" , "error" , err , "attempt" , e .attempt , "retry_in" , diff .String ())
73+ log .Info ("provider still offline" , "error" , err , "attempt" , p .attempt , "retry_in" , backoff .String ())
7474 }
7575 return
7676 }
7777
78- e .online = online
78+ p .online = online
7979 if ! online {
80- e . retryAt = time . Now (). Add ( backoff ( 1 ) )
81- e . onlineAt = time.Time {}
82- diff : = time .Until ( e . retryAt )
83- log .Info ("endpoint offline" , "error" , err , "retry_in" , diff .String ())
80+ backoff := nextAttemptDelay ( 1 )
81+ p . retryAt = time .Now (). Add ( backoff )
82+ p . onlineAt = time.Time {}
83+ log .Info ("provider offline" , "error" , err , "attempt" , p . attempt , " retry_in" , backoff .String ())
8484 } else {
85- log .Info ("endpoint online" , "client_version" , e .clientVersion )
86- e .onlineAt = time .Now ()
87- e .retryAt = time.Time {}
88- e .attempt = 0
85+ log .Info ("provider online" , "client_version" , p .clientVersion )
86+ p .onlineAt = time .Now ()
87+ p .retryAt = time.Time {}
88+ p .attempt = 0
8989 }
9090}
9191
0 commit comments