mirror of
https://github.com/gravitl/netmaker.git
synced 2024-09-20 23:36:18 +08:00
edited logs
This commit is contained in:
parent
28ea854842
commit
10872c4e25
|
@ -1,7 +1,6 @@
|
|||
package command
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -156,7 +155,7 @@ func Push(cfg config.ClientConfig) error {
|
|||
for _, network := range networks {
|
||||
err = functions.Push(network)
|
||||
if err != nil {
|
||||
log.Printf("error pushing network configs for "+network+" network: ", err)
|
||||
ncutils.PrintLog("error pushing network configs for network: "+network+"\n"+err.Error(), 1)
|
||||
} else {
|
||||
ncutils.PrintLog("pushed network config for "+network, 1)
|
||||
}
|
||||
|
@ -187,7 +186,7 @@ func Pull(cfg config.ClientConfig) error {
|
|||
for _, network := range networks {
|
||||
_, err = functions.Pull(network, true)
|
||||
if err != nil {
|
||||
log.Printf("Error pulling network config for "+network+" network: ", err)
|
||||
ncutils.PrintLog("Error pulling network config for network: "+network+"\n"+err.Error(), 1)
|
||||
} else {
|
||||
ncutils.PrintLog("pulled network config for "+network, 1)
|
||||
}
|
||||
|
|
24
netclient/ncutils/util.go
Normal file
24
netclient/ncutils/util.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package ncutils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// BackOff - back off any function while there is an error
|
||||
func BackOff(isExponential bool, maxTime int, f interface{}) (interface{}, error) {
|
||||
// maxTime seconds
|
||||
startTime := time.Now()
|
||||
sleepTime := time.Second
|
||||
for time.Now().Before(startTime.Add(time.Second * time.Duration(maxTime))) {
|
||||
if result, err := f.(func() (interface{}, error))(); err == nil {
|
||||
return result, nil
|
||||
}
|
||||
time.Sleep(sleepTime)
|
||||
if isExponential {
|
||||
sleepTime = sleepTime << 1
|
||||
}
|
||||
PrintLog("retrying...", 1)
|
||||
}
|
||||
return nil, fmt.Errorf("could not find result")
|
||||
}
|
Loading…
Reference in a new issue