Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
refactor getasyncentity
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Aug 6, 2019
1 parent 051b516 commit 5f4fc1e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 4 additions & 2 deletions cmd/apps/expapp/expapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func init() {

}

//batch created a batch of products to query
//batch created a batch of apps to query
func batch(entities []app, entityType string, pwg *sync.WaitGroup, mu *sync.Mutex) {

defer pwg.Done()
Expand All @@ -52,7 +52,9 @@ func batch(entities []app, entityType string, pwg *sync.WaitGroup, mu *sync.Mute
bwg.Add(len(entities))

for _, entity := range entities {
go shared.GetAsyncEntity(entity.AppID, entityType, &bwg, mu)
u, _ := url.Parse(shared.BaseURL)
u.Path = path.Join(u.Path, shared.RootArgs.Org, entityType, entity.AppID)
go shared.GetAsyncEntity(u.String(), &bwg, mu)
}
bwg.Wait()
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/products/expprod/expprod.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ func batch(entities []apiProduct, entityType string, pwg *sync.WaitGroup, mu *sy
bwg.Add(len(entities))

for _, entity := range entities {
go shared.GetAsyncEntity(url.PathEscape(entity.Name), entityType, &bwg, mu)
u, _ := url.Parse(shared.BaseURL)
u.Path = path.Join(u.Path, shared.RootArgs.Org, entityType, url.PathEscape(entity.Name))
go shared.GetAsyncEntity(u.String(), &bwg, mu)
}
bwg.Wait()
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,27 +537,27 @@ func WriteByteArrayToFile(exportFile string, fileAppend bool, payload []byte) er
}

//GetAsync stores results for each entity in a list
func GetAsyncEntity(entityName string, entityType string, wg *sync.WaitGroup, mu *sync.Mutex) {
func GetAsyncEntity(entityURL string, wg *sync.WaitGroup, mu *sync.Mutex) {

//this is a two step process - 1) get entity details 2) store in byte[][]
defer wg.Done()
var respBody []byte

u, _ := url.Parse(BaseURL)
u.Path = path.Join(u.Path, RootArgs.Org, entityType, entityName)
//u, _ := url.Parse(BaseURL)
//u.Path = path.Join(u.Path, RootArgs.Org, entityType, entityName)
//don't print to sysout
respBody, err := HttpClient(false, u.String())
respBody, err := HttpClient(false, entityURL)

if err != nil {
Error.Fatalln("Error with entity: %s", entityName)
Error.Fatalln("Error with entity: %s", entityURL)
Error.Fatalln(err)
return
}

mu.Lock()
EntityPayloadList = append(EntityPayloadList, respBody)
mu.Unlock()
Info.Printf("Completed entity: %s", entityName)
Info.Printf("Completed entity: %s", entityURL)
}

//FetchAyncBundle can download a shared flow or a proxy bundle
Expand Down

0 comments on commit 5f4fc1e

Please sign in to comment.