Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Unified Diff: server/settings/settings.go

Issue 1748933002: Retry RPC deadlines when fetching GAE settings. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@simplify-lazyslot
Patch Set: move retry to settings.go Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « common/lazyslot/lazyslot.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/settings/settings.go
diff --git a/server/settings/settings.go b/server/settings/settings.go
index bd05fa0503978292d68f0c79694076e15adfca7a..678c42cf4926a13aac0a32b10701f60f136b365b 100644
--- a/server/settings/settings.go
+++ b/server/settings/settings.go
@@ -19,7 +19,9 @@ import (
"golang.org/x/net/context"
+ "github.com/luci/luci-go/common/clock"
"github.com/luci/luci-go/common/lazyslot"
+ "github.com/luci/luci-go/common/retry"
)
var (
@@ -116,20 +118,34 @@ func New(storage Storage) *Settings {
return &Settings{
storage: storage,
values: lazyslot.Slot{
- Fetcher: func(c context.Context, _ lazyslot.Value) (lazyslot.Value, error) {
- bundle, err := storage.FetchAllSettings(c)
+ Timeout: 15 * time.Second, // retry for 15 sec at most
+ Fetcher: func(c context.Context, _ lazyslot.Value) (result lazyslot.Value, err error) {
+ err = retry.Retry(c, retry.TransientOnly(retry.Default), func() error {
+ ctx, _ := clock.WithTimeout(c, 2*time.Second) // trigger a retry after 2 sec RPC timeout
+ result, err = attemptToFetchSettings(ctx, storage)
+ return err
+ }, nil)
if err != nil {
- return lazyslot.Value{}, err
+ result = lazyslot.Value{}
}
- return lazyslot.Value{
- Value: bundle,
- Expiration: bundle.Exp,
- }, nil
+ return
},
},
}
}
+// attemptToFetchSettings is called in a retry loop when loading settings.
+func attemptToFetchSettings(c context.Context, storage Storage) (lazyslot.Value, error) {
+ bundle, err := storage.FetchAllSettings(c)
+ if err != nil {
+ return lazyslot.Value{}, err
+ }
+ return lazyslot.Value{
+ Value: bundle,
+ Expiration: bundle.Exp,
+ }, nil
+}
+
// GetStorage returns underlying Storage instance.
func (s *Settings) GetStorage() Storage {
return s.storage
« no previous file with comments | « common/lazyslot/lazyslot.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698