mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Remove the retries on error in remote resources.Get
Fixes #9271 See #9259
This commit is contained in:
parent
e4d6ec94b5
commit
3bc6830411
4 changed files with 8 additions and 31 deletions
22
cache/filecache/filecache.go
vendored
22
cache/filecache/filecache.go
vendored
|
@ -48,9 +48,6 @@ type Cache struct {
|
||||||
// 0 is effectively turning this cache off.
|
// 0 is effectively turning this cache off.
|
||||||
maxAge time.Duration
|
maxAge time.Duration
|
||||||
|
|
||||||
// Number of retries on create error.
|
|
||||||
retries int
|
|
||||||
|
|
||||||
// When set, we just remove this entire root directory on expiration.
|
// When set, we just remove this entire root directory on expiration.
|
||||||
pruneAllRootDir string
|
pruneAllRootDir string
|
||||||
|
|
||||||
|
@ -87,12 +84,11 @@ type ItemInfo struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCache creates a new file cache with the given filesystem and max age.
|
// NewCache creates a new file cache with the given filesystem and max age.
|
||||||
func NewCache(fs afero.Fs, maxAge time.Duration, retries int, pruneAllRootDir string) *Cache {
|
func NewCache(fs afero.Fs, maxAge time.Duration, pruneAllRootDir string) *Cache {
|
||||||
return &Cache{
|
return &Cache{
|
||||||
Fs: fs,
|
Fs: fs,
|
||||||
nlocker: &lockTracker{Locker: locker.NewLocker(), seen: make(map[string]struct{})},
|
nlocker: &lockTracker{Locker: locker.NewLocker(), seen: make(map[string]struct{})},
|
||||||
maxAge: maxAge,
|
maxAge: maxAge,
|
||||||
retries: retries,
|
|
||||||
pruneAllRootDir: pruneAllRootDir,
|
pruneAllRootDir: pruneAllRootDir,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,14 +180,7 @@ func (c *Cache) GetOrCreate(id string, create func() (io.ReadCloser, error)) (It
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
for i := -1; i < c.retries; i++ {
|
|
||||||
r, err = create()
|
r, err = create()
|
||||||
if err == nil || c.retries == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return info, nil, err
|
return info, nil, err
|
||||||
}
|
}
|
||||||
|
@ -227,14 +216,7 @@ func (c *Cache) GetOrCreateBytes(id string, create func() ([]byte, error)) (Item
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
for i := -1; i < c.retries; i++ {
|
|
||||||
b, err = create()
|
b, err = create()
|
||||||
if err == nil || c.retries == 0 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return info, nil, err
|
return info, nil, err
|
||||||
}
|
}
|
||||||
|
@ -388,7 +370,7 @@ func NewCaches(p *helpers.PathSpec) (Caches, error) {
|
||||||
pruneAllRootDir = "pkg"
|
pruneAllRootDir = "pkg"
|
||||||
}
|
}
|
||||||
|
|
||||||
m[k] = NewCache(bfs, v.MaxAge, v.retries, pruneAllRootDir)
|
m[k] = NewCache(bfs, v.MaxAge, pruneAllRootDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
5
cache/filecache/filecache_config.go
vendored
5
cache/filecache/filecache_config.go
vendored
|
@ -75,7 +75,6 @@ var defaultCacheConfigs = Configs{
|
||||||
cacheKeyGetResource: Config{
|
cacheKeyGetResource: Config{
|
||||||
MaxAge: -1, // Never expire
|
MaxAge: -1, // Never expire
|
||||||
Dir: cacheDirProject,
|
Dir: cacheDirProject,
|
||||||
retries: 3, // Retries on error getting the remote resource.
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,10 +90,6 @@ type Config struct {
|
||||||
// Will resources/_gen will get its own composite filesystem that
|
// Will resources/_gen will get its own composite filesystem that
|
||||||
// also checks any theme.
|
// also checks any theme.
|
||||||
isResourceDir bool
|
isResourceDir bool
|
||||||
|
|
||||||
// Number of retries when errors occurs when creating the element,
|
|
||||||
// only used for remote resources.
|
|
||||||
retries int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetJSONCache gets the file cache for getJSON.
|
// GetJSONCache gets the file cache for getJSON.
|
||||||
|
|
2
cache/filecache/filecache_test.go
vendored
2
cache/filecache/filecache_test.go
vendored
|
@ -276,7 +276,7 @@ func TestFileCacheReadOrCreateErrorInRead(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cache := NewCache(afero.NewMemMapFs(), 100*time.Hour, 0, "")
|
cache := NewCache(afero.NewMemMapFs(), 100*time.Hour, "")
|
||||||
|
|
||||||
const id = "a32"
|
const id = "a32"
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ func TestScpGetRemote(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
c := qt.New(t)
|
c := qt.New(t)
|
||||||
fs := new(afero.MemMapFs)
|
fs := new(afero.MemMapFs)
|
||||||
cache := filecache.NewCache(fs, 100, 0, "")
|
cache := filecache.NewCache(fs, 100, "")
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
path string
|
path string
|
||||||
|
|
Loading…
Reference in a new issue