Skip to content

Commit

Permalink
Status check added
Browse files Browse the repository at this point in the history
  • Loading branch information
pdarvasi committed Dec 18, 2017
1 parent 66d52cd commit e77ea4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
BINARY=pollprogress
VERSION=0.1.2
VERSION=0.1.3
OWNER=$(shell glu info| sed -n "s/Owner: //p")

deps:
go get -u github.com/kardianos/govendor
go get -u github.com/gliderlabs/glu
go get -u github.com/sethgrid/multibar

build:
GOOS=linux CGO_ENABLED=0 go build -o build/Linux/${BINARY} main.go
Expand Down
21 changes: 16 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"sync"
"time"
"math"

"github.com/sethgrid/multibar"

Expand All @@ -33,11 +34,21 @@ func poll(cmd string) (int, int, error) {
return 0, 0, errors.New(fmt.Sprintf("Cannot convert actual copy progress to int: %s", parts[0]))
}

sum, err := strconv.Atoi(strings.TrimSpace(parts[1]))
secondPart := strings.Split(parts[1],"\n")

sum, err := strconv.Atoi(strings.TrimSpace(secondPart[0]))
if err != nil {
return 0, 0, errors.New(fmt.Sprintf("Cannot convert total blob sizeto int: %s", parts[1]))
return 0, 0, errors.New(fmt.Sprintf("Cannot convert total blob size to int: %s", secondPart[0]))
}
return act, sum, nil

status := strings.TrimSpace(secondPart[1])
switch status {
case
"pending",
"success":
return act, sum, nil
}
return 0, 0, errors.New(fmt.Sprintf("Copy operation status is invalid: %s", status))
}

func main() {
Expand All @@ -48,7 +59,7 @@ func main() {

data, err := ioutil.ReadFile(os.Args[1])
if err != nil {
log.Fatalf("Cloudn't read file: %v", err)
log.Fatalf("Couldn't read file: %v", err)
}
var obj map[string]string
err = yaml.Unmarshal([]byte(data), &obj)
Expand All @@ -70,7 +81,7 @@ func main() {
log.Printf("Error finding the total size of the vhd in Storage Account: %s, error: %s", task, err.Error())
_, sum, err = poll(cmd)
}
log.Printf("Blob size of vhd in Storage Account of %s is: %d", task, sum)
log.Printf("Blob size of vhd in Storage Account of %s is: %f GB", task, float64(sum) / math.Pow(1024,3))
totals[task] = sum
}(task, cmd)
}
Expand Down

0 comments on commit e77ea4b

Please sign in to comment.