refactor(busretry): unexport the maximum retry delay
- commit
- e0d48191cb0f344db37cc6476d5b4db6a5897d9c
- author
- brice · · 2026-10-08 09:02 UTC
- parent
- 508f6f4
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +7 -7
M internal/adapters/busretry/busretry.go +6 -6
| @@ -11,12 +11,12 @@ import ( | |||
| 11 | 11 | "github.com/bnema/zerowrap" | |
| 12 | 12 | ) | |
| 13 | 13 | ||
| 14 | - | // Max bounds the delay between attempts. | |
| 15 | - | const Max = time.Minute | |
| 14 | + | // maxDelay bounds the delay between attempts. | |
| 15 | + | const maxDelay = time.Minute | |
| 16 | 16 | ||
| 17 | 17 | // Run calls attempt until ctx ends. When attempt returns, it waits retry, | |
| 18 | - | // doubling up to Max on each failure, and calls it again. An attempt that | |
| 19 | - | // ran longer than Max before failing starts the delay over: its failure is | |
| 18 | + | // doubling up to maxDelay on each failure, and calls it again. An attempt that | |
| 19 | + | // ran longer than maxDelay before failing starts the delay over: its failure is | |
| 20 | 20 | // new, not a retry streak. what names the feature in logs ("X ignored until | |
| 21 | 21 | // the next attempt"); a failure is warned once per distinct error, then | |
| 22 | 22 | // logged at debug level. | |
| @@ -32,7 +32,7 @@ func Run(ctx context.Context, retry time.Duration, what string, log zerowrap.Log | |||
| 32 | 32 | if err == nil { | |
| 33 | 33 | err = errors.New(what + " stopped") | |
| 34 | 34 | } | |
| 35 | - | if time.Since(start) > Max { | |
| 35 | + | if time.Since(start) > maxDelay { | |
| 36 | 36 | delay, last = retry, "" | |
| 37 | 37 | } | |
| 38 | 38 | if msg := err.Error(); msg != last { | |
| @@ -46,6 +46,6 @@ func Run(ctx context.Context, retry time.Duration, what string, log zerowrap.Log | |||
| 46 | 46 | return | |
| 47 | 47 | case <-time.After(delay): | |
| 48 | 48 | } | |
| 49 | - | delay = min(2*delay, Max) | |
| 49 | + | delay = min(2*delay, maxDelay) | |
| 50 | 50 | } | |
| 51 | 51 | } | |
| @@ -11,12 +11,12 @@ import ( | |||||
| 11 | "github.com/bnema/zerowrap" | 11 | "github.com/bnema/zerowrap" | ||
| 12 | ) | 12 | ) | ||
| 13 | 13 | ||||
| 14 | - | // Max bounds the delay between attempts. | 14 | + | // maxDelay bounds the delay between attempts. |
| 15 | - | const Max = time.Minute | 15 | + | const maxDelay = time.Minute |
| 16 | 16 | ||||
| 17 | // Run calls attempt until ctx ends. When attempt returns, it waits retry, | 17 | // Run calls attempt until ctx ends. When attempt returns, it waits retry, | ||
| 18 | - | // doubling up to Max on each failure, and calls it again. An attempt that | 18 | + | // doubling up to maxDelay on each failure, and calls it again. An attempt that |
| 19 | - | // ran longer than Max before failing starts the delay over: its failure is | 19 | + | // ran longer than maxDelay before failing starts the delay over: its failure is |
| 20 | // new, not a retry streak. what names the feature in logs ("X ignored until | 20 | // new, not a retry streak. what names the feature in logs ("X ignored until | ||
| 21 | // the next attempt"); a failure is warned once per distinct error, then | 21 | // the next attempt"); a failure is warned once per distinct error, then | ||
| 22 | // logged at debug level. | 22 | // logged at debug level. | ||
| @@ -32,7 +32,7 @@ func Run(ctx context.Context, retry time.Duration, what string, log zerowrap.Log | |||||
| 32 | if err == nil { | 32 | if err == nil { | ||
| 33 | err = errors.New(what + " stopped") | 33 | err = errors.New(what + " stopped") | ||
| 34 | } | 34 | } | ||
| 35 | - | if time.Since(start) > Max { | 35 | + | if time.Since(start) > maxDelay { |
| 36 | delay, last = retry, "" | 36 | delay, last = retry, "" | ||
| 37 | } | 37 | } | ||
| 38 | if msg := err.Error(); msg != last { | 38 | if msg := err.Error(); msg != last { | ||
| @@ -46,6 +46,6 @@ func Run(ctx context.Context, retry time.Duration, what string, log zerowrap.Log | |||||
| 46 | return | 46 | return | ||
| 47 | case <-time.After(delay): | 47 | case <-time.After(delay): | ||
| 48 | } | 48 | } | ||
| 49 | - | delay = min(2*delay, Max) | 49 | + | delay = min(2*delay, maxDelay) |
| 50 | } | 50 | } | ||
| 51 | } | 51 | } | ||
M internal/adapters/screensaver/screensaver.go +1 -1
| @@ -53,7 +53,7 @@ type Reports struct { | |||
| 53 | 53 | ||
| 54 | 54 | // Serve runs the service until ctx ends. When the bus goes or another | |
| 55 | 55 | // program owns the name, it tries again after retry, doubling up to | |
| 56 | - | // busretry.Max, so a restarted bus or a released name is picked up. | |
| 56 | + | // a minute, so a restarted bus or a released name is picked up. | |
| 57 | 57 | func Serve(ctx context.Context, address string, r Reports, retry time.Duration, log zerowrap.Logger) { | |
| 58 | 58 | busretry.Run(ctx, retry, "D-Bus idle inhibitors", log, func(ctx context.Context) error { | |
| 59 | 59 | s, err := New(ctx, address, log) | |
| @@ -53,7 +53,7 @@ type Reports struct { | |||||
| 53 | 53 | ||||
| 54 | // Serve runs the service until ctx ends. When the bus goes or another | 54 | // Serve runs the service until ctx ends. When the bus goes or another | ||
| 55 | // program owns the name, it tries again after retry, doubling up to | 55 | // program owns the name, it tries again after retry, doubling up to | ||
| 56 | - | // busretry.Max, so a restarted bus or a released name is picked up. | 56 | + | // a minute, so a restarted bus or a released name is picked up. |
| 57 | func Serve(ctx context.Context, address string, r Reports, retry time.Duration, log zerowrap.Logger) { | 57 | func Serve(ctx context.Context, address string, r Reports, retry time.Duration, log zerowrap.Logger) { | ||
| 58 | busretry.Run(ctx, retry, "D-Bus idle inhibitors", log, func(ctx context.Context) error { | 58 | busretry.Run(ctx, retry, "D-Bus idle inhibitors", log, func(ctx context.Context) error { | ||
| 59 | s, err := New(ctx, address, log) | 59 | s, err := New(ctx, address, log) | ||