Skip to content

Commit

Permalink
change to ItemStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
sppatel committed Sep 22, 2022
1 parent 6f2cd33 commit 570f097
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cli/internal/cache/async_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *asyncCache) Fetch(target string, key string, files []string) (bool, []s
return c.realCache.Fetch(target, key, files)
}

func (c *asyncCache) Exists(key string) (State, error) {
func (c *asyncCache) Exists(key string) (ItemStatus, error) {
return c.realCache.Exists(key)
}

Expand Down
10 changes: 5 additions & 5 deletions cli/internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ type Cache interface {
// Fetch returns true if there is a cache it. It is expected to move files
// into their correct position as a side effect
Fetch(target string, hash string, files []string) (bool, []string, int, error)
Exists(hash string) (State, error)
Exists(hash string) (ItemStatus, error)
// Put caches files for a given hash
Put(target string, hash string, duration int, files []string) error
Clean(target string)
CleanAll()
Shutdown()
}

// State holds whether artifacts exists for a given hash on local
// ItemStatus holds whether artifacts exists for a given hash on local
// and/or remote caching server
type State struct {
type ItemStatus struct {
Local bool `json:"local"`
Remote bool `json:"remote"`
}
Expand Down Expand Up @@ -279,8 +279,8 @@ func (mplex *cacheMultiplexer) Fetch(target string, key string, files []string)
return false, files, 0, nil
}

func (mplex *cacheMultiplexer) Exists(target string) (State, error) {
syncCacheState := State{}
func (mplex *cacheMultiplexer) Exists(target string) (ItemStatus, error) {
syncCacheState := ItemStatus{}
for _, cache := range mplex.caches {
cacheState, err := cache.Exists(target)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cli/internal/cache/cache_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ func (f *fsCache) Fetch(target, hash string, _unusedOutputGlobs []string) (bool,
return true, nil, meta.Duration, nil
}

func (f *fsCache) Exists(hash string) (State, error) {
func (f *fsCache) Exists(hash string) (ItemStatus, error) {
cachedFolder := filepath.Join(f.cacheDirectory, hash)

if !fs.PathExists(cachedFolder) {
return State{Local: false}, nil
return ItemStatus{Local: false}, nil
}

return State{Local: true}, nil
return ItemStatus{Local: true}, nil
}

func (f *fsCache) logFetch(hit bool, hash string, duration int) {
Expand Down
6 changes: 3 additions & 3 deletions cli/internal/cache/cache_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ func (cache *httpCache) Fetch(target, key string, _unusedOutputGlobs []string) (
return hit, files, duration, err
}

func (cache *httpCache) Exists(key string) (State, error) {
func (cache *httpCache) Exists(key string) (ItemStatus, error) {
cache.requestLimiter.acquire()
defer cache.requestLimiter.release()
hit, err := cache.exists(key)
if err != nil {
return State{}, fmt.Errorf("failed to verify files from HTTP cache: %w", err)
return ItemStatus{}, fmt.Errorf("failed to verify files from HTTP cache: %w", err)
}
return State{Remote: hit}, err
return ItemStatus{Remote: hit}, err
}

func (cache *httpCache) logFetch(hit bool, hash string, duration int) {
Expand Down
4 changes: 2 additions & 2 deletions cli/internal/cache/cache_noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ func (c *noopCache) Put(target string, key string, duration int, files []string)
func (c *noopCache) Fetch(target string, key string, files []string) (bool, []string, int, error) {
return false, nil, 0, nil
}
func (c *noopCache) Exists(key string) (State, error) {
return State{}, nil
func (c *noopCache) Exists(key string) (ItemStatus, error) {
return ItemStatus{}, nil
}

func (c *noopCache) Clean(target string) {}
Expand Down
8 changes: 4 additions & 4 deletions cli/internal/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ func (tc *testCache) Fetch(target string, hash string, files []string) (bool, []
return false, nil, 0, nil
}

func (tc *testCache) Exists(hash string) (State, error) {
func (tc *testCache) Exists(hash string) (ItemStatus, error) {
if tc.disabledErr != nil {
return State{}, nil
return ItemStatus{}, nil
}
_, ok := tc.entries[hash]
if ok {
return State{Local: true}, nil
return ItemStatus{Local: true}, nil
}
return State{}, nil
return ItemStatus{}, nil
}

func (tc *testCache) Put(target string, hash string, duration int, files []string) error {
Expand Down
22 changes: 11 additions & 11 deletions cli/internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,17 +706,17 @@ func (r *run) executeTasks(ctx gocontext.Context, g *completeGraph, rs *runSpec,
}

type hashedTask struct {
TaskID string `json:"taskId"`
Task string `json:"task"`
Package string `json:"package"`
Hash string `json:"hash"`
CacheState cache.State `json:"cacheState"`
Command string `json:"command"`
Outputs []string `json:"outputs"`
LogFile string `json:"logFile"`
Dir string `json:"directory"`
Dependencies []string `json:"dependencies"`
Dependents []string `json:"dependents"`
TaskID string `json:"taskId"`
Task string `json:"task"`
Package string `json:"package"`
Hash string `json:"hash"`
CacheState cache.ItemStatus `json:"cacheState"`
Command string `json:"command"`
Outputs []string `json:"outputs"`
LogFile string `json:"logFile"`
Dir string `json:"directory"`
Dependencies []string `json:"dependencies"`
Dependents []string `json:"dependents"`
}

func (r *run) executeDryRun(ctx gocontext.Context, engine *core.Scheduler, g *completeGraph, taskHashes *taskhash.Tracker, rs *runSpec) ([]hashedTask, error) {
Expand Down

0 comments on commit 570f097

Please # to comment.