Skip to content

Commit

Permalink
refactor poll logic
Browse files Browse the repository at this point in the history
  • Loading branch information
keyki committed May 18, 2018
1 parent 2be1ba3 commit 1f398d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BINARY=pollprogress
VERSION=0.2.1
VERSION=0.2.2
OWNER=$(shell glu info| sed -n "s/Owner: //p")

deps:
Expand Down
28 changes: 14 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ func main() {
wg := &sync.WaitGroup{}
wg.Add(len(tasks))

totals := map[string]int{}
log.Println("Getting blob sizes..")
for storageAccount, cmd := range tasks {
go func(storageAccount, cmd string) {
defer wg.Done()
_, sum, err := poll(cmd)
for err != nil {
time.Sleep(time.Second * 1)
log.Printf("Error finding the total size of the vhd in Storage Account: %s, error: %s", storageAccount, err.Error())
sum := 0
for sum == 0 {
_, sum, err = poll(cmd)
if err != nil {
log.Printf("Error finding the total size of the vhd in Storage Account: %s, error: %s", storageAccount, err.Error())
time.Sleep(time.Second * 1)
}
}
log.Printf("Blob size of vhd in Storage Account of %s is: %f GB", storageAccount, float64(sum)/math.Pow(1024, 3))
totals[storageAccount] = sum
}(storageAccount, cmd)
}
wg.Wait()
Expand All @@ -88,21 +88,21 @@ func main() {
for storageAccount, cmd := range tasks {
go func(storageAccount, cmd string) {
defer wg.Done()
act, sum, err := poll(cmd)
if err == nil {
log.Printf("Copy status to Storage Account of %s is: (%d/%d) %.2f%% ", storageAccount, act, sum, (float64(act)/float64(sum))*100)
}
for act < sum || err != nil {
time.Sleep(time.Second * 10)
act, sum := 0, 0
var err error
for act == 0 || sum == 0 || act < sum {
act, sum, err = poll(cmd)
if err == nil {
if err != nil {
log.Printf("Failed to check the copy status to Storage Account %s, err: %s", storageAccount, err.Error())
} else {
log.Printf("Copy status to Storage Account of %s is: (%d/%d) %.2f%% ", storageAccount, act, sum, (float64(act)/float64(sum))*100)
}
time.Sleep(time.Second * 10)
}
}(storageAccount, cmd)
}

wg.Wait()

fmt.Println("DONE")
log.Println("DONE")
}

0 comments on commit 1f398d1

Please sign in to comment.