Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Fix cache refresh messages #9

Merged
merged 3 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cache/aws_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,26 @@ func (g *AwsEc2Cache) Len() int {
}

// Refresh refreshes resources
func (g *AwsEc2Cache) Refresh(force bool) (err error) {
func (g *AwsEc2Cache) Refresh(force bool) (refreshed bool, err error) {
if g.cacheOutdated() == false && force == false {
g.Read()
return nil
return false, nil
}

g.Provider.Init()

result, err := g.Provider.GetResources()
if err != nil {
return err
return false, err
}
for _, r := range result {
g.Result = append(g.Result, r.(*resources.Ec2Instance))
}
err = g.Save()
if err != nil {
return err
return false, err
}
return nil
return true, nil
}

// Save saves the cache to cache file
Expand Down
2 changes: 1 addition & 1 deletion cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "github.com/zendesk/goship/resources"
type GoshipCache interface {
CacheName() string
Resources() []resources.Resource
Refresh(bool) error
Refresh(bool) (bool, error)
Save() error
Read() error
Len() int
Expand Down
11 changes: 9 additions & 2 deletions cache/cache_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ func (cl *GlobalCacheList) RefreshInParallel(force bool) error {
go func(cache GoshipCache) {
refreshStart := time.Now()
defer wg.Done()
cache.Refresh(force)
refreshed, err := cache.Refresh(force)
if err != nil {
color.PrintRed(fmt.Sprintf("Error while refreshing cache: %s\n", err))
}
refreshElapsed := time.Since(refreshStart)
if config.GlobalConfig.Verbose {
color.PrintGreen(fmt.Sprintf("[%s] Cache refresh in: %s. Read %d instances\n", cache.CacheName(), refreshElapsed, cache.Len()))
if refreshed {
color.PrintGreen(fmt.Sprintf("[%s] Cache refresh took: %s. Read %d instances\n", cache.CacheName(), refreshElapsed, cache.Len()))
} else {
color.PrintGreen(fmt.Sprintf("[%s] Cache read took: %s. Read %d instances\n", cache.CacheName(), refreshElapsed, cache.Len()))
}
}
}(c)
}
Expand Down