Capture error on Run Log Cache Exists
This commit is contained in:
parent
a89d50fc63
commit
e644dc50d6
2 changed files with 19 additions and 8 deletions
|
|
@ -29,7 +29,7 @@ import (
|
|||
)
|
||||
|
||||
type runLogCache interface {
|
||||
Exists(key string) bool
|
||||
Exists(key string) (bool, error)
|
||||
Create(key string, r io.Reader) error
|
||||
Open(key string) (*zip.ReadCloser, error)
|
||||
}
|
||||
|
|
@ -38,11 +38,17 @@ type rlc struct {
|
|||
cacheDir string
|
||||
}
|
||||
|
||||
func (c rlc) Exists(key string) bool {
|
||||
if _, err := os.Stat(c.filepath(key)); err != nil {
|
||||
return false
|
||||
func (c rlc) Exists(key string) (bool, error) {
|
||||
_, err := os.Stat(c.filepath(key))
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
return true
|
||||
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return false, fmt.Errorf("checking cache entry: %v", err)
|
||||
}
|
||||
|
||||
func (c rlc) Create(key string, content io.Reader) error {
|
||||
|
|
@ -453,7 +459,12 @@ func getLog(httpClient *http.Client, logURL string) (io.ReadCloser, error) {
|
|||
|
||||
func getRunLog(cache runLogCache, httpClient *http.Client, repo ghrepo.Interface, run *shared.Run, attempt uint64) (*zip.ReadCloser, error) {
|
||||
cacheKey := fmt.Sprintf("%d-%d", run.ID, run.StartedTime().Unix())
|
||||
if !cache.Exists(cacheKey) {
|
||||
isCached, err := cache.Exists(cacheKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !isCached {
|
||||
// Run log does not exist in cache so retrieve and store it
|
||||
logURL := fmt.Sprintf("%srepos/%s/actions/runs/%d/logs",
|
||||
ghinstance.RESTPrefix(repo.RepoHost()), ghrepo.FullName(repo), run.ID)
|
||||
|
|
|
|||
|
|
@ -1495,8 +1495,8 @@ func Test_attachRunLog(t *testing.T) {
|
|||
|
||||
type testRunLogCache struct{}
|
||||
|
||||
func (testRunLogCache) Exists(path string) bool {
|
||||
return false
|
||||
func (testRunLogCache) Exists(path string) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
func (testRunLogCache) Create(path string, content io.Reader) error {
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue