| Index: appengine/gaeconfig/default.go
|
| diff --git a/appengine/gaeconfig/default.go b/appengine/gaeconfig/default.go
|
| index 869b558c5c23b682103e7bf8797f1b67dbfe69f3..e6e90a99eb5b39238cb5c553c84616775403000b 100644
|
| --- a/appengine/gaeconfig/default.go
|
| +++ b/appengine/gaeconfig/default.go
|
| @@ -17,6 +17,7 @@ import (
|
| "github.com/luci/luci-go/server/config/erroring"
|
| "github.com/luci/luci-go/server/config/testconfig"
|
| "github.com/luci/luci-go/server/config/textproto"
|
| + "github.com/luci/luci-go/server/router"
|
|
|
| "github.com/luci/gae/service/info"
|
|
|
| @@ -31,6 +32,30 @@ var ErrNotConfigured = errors.New("config service URL is not set in settings")
|
| // local dev appserver model. See New for details.
|
| const devCfgDir = "devcfg"
|
|
|
| +// InstallCacheCronHandler installs the configuration service datastore caching
|
| +// cron handler. This must be installed, and an associated cron must be set up,
|
| +// if datastore caching is enabled.
|
| +//
|
| +// The cron should be configured to hit the handler at:
|
| +// /admin/config/cache/manager
|
| +func InstallCacheCronHandler(r *router.Router, base router.MiddlewareChain) {
|
| + installCacheCronHandlerImpl(r, base, nil)
|
| +}
|
| +
|
| +// Install our cache cron handler into the supplied Router.
|
| +//
|
| +// bf is a generator function used to get the primary (service) Backend to build
|
| +// on top of. If nil, the "production" (one used by Use) Backend will be used.
|
| +func installCacheCronHandlerImpl(r *router.Router, base router.MiddlewareChain, backend config.Backend) {
|
| + base = base.Extend(func(c *router.Context, next router.Handler) {
|
| + // Install our Backend into our Context.
|
| + c.Context = installConfigBackend(c.Context, mustFetchCachedSettings(c.Context), backend, true)
|
| + next(c)
|
| + })
|
| +
|
| + dsCache.InstallCronRoute("/admin/config/cache/manager", r, base)
|
| +}
|
| +
|
| // Use installs the default luci-config client.
|
| //
|
| // The client is configured to use luci-config URL specified in the settings,
|
| @@ -53,10 +78,10 @@ const devCfgDir = "devcfg"
|
| func Use(c context.Context) context.Context { return useImpl(c, nil) }
|
|
|
| func useImpl(c context.Context, backend config.Backend) context.Context {
|
| - return installConfigBackend(c, mustFetchCachedSettings(c), backend)
|
| + return installConfigBackend(c, mustFetchCachedSettings(c), backend, false)
|
| }
|
|
|
| -func installConfigBackend(c context.Context, s *Settings, backend config.Backend) context.Context {
|
| +func installConfigBackend(c context.Context, s *Settings, backend config.Backend, dsCron bool) context.Context {
|
| if backend == nil {
|
| // Non-testing, build a Backend.
|
| backend = getPrimaryBackend(c, s)
|
| @@ -76,6 +101,26 @@ func installConfigBackend(c context.Context, s *Settings, backend config.Backend
|
| // Add a ProcCache, backed by memcache.
|
| backend = caching.ProcCache(backend, exp)
|
| backend = memcacheBackend(backend, exp)
|
| +
|
| + // If our datastore cache is enabled, install a handler for refresh. This
|
| + // will be loaded by dsCache's "HandlerFunc".
|
| + if s.DatastoreCacheMode != dsCacheDisabled {
|
| + dsc := datastoreCache{
|
| + refreshInterval: exp,
|
| + failOpen: s.DatastoreCacheMode == dsCacheEnabled,
|
| + }
|
| +
|
| + if !dsCron {
|
| + // For non-cron, install the datastore cache Backend.
|
| + backend = dsc.getBackend(backend)
|
| + } else {
|
| + // For cron, do not install the datastore cache Backend. Instead,
|
| + // install a lasting Handler into the Context to be used for cache
|
| + // resolution. This is necessary since resolution calls will not be
|
| + // the result of an actual resolution command (e.g., cache.Get).
|
| + c = dsc.withHandler(c, datastoreCronLoader(backend), dsRPCDeadline)
|
| + }
|
| + }
|
| }
|
|
|
| c = config.WithBackend(c, backend)
|
|
|