cmd/revid-cli: use time.Duration for durations

This commit is contained in:
Dan Kortschak 2018-06-08 21:52:11 +09:30
parent d457256931
commit 41eb46c702
1 changed files with 14 additions and 12 deletions

View File

@ -72,11 +72,10 @@ const (
// Other misc consts
const (
progName = "revid-cli"
netSendRetryTime = 5
sleepTime = 2 * 43200
defaultRunDuration = 2 * 43200
revidStopTime = 5
prepTime = 20
netSendRetryTime = 5 * time.Second
defaultRunDuration = 24 * time.Hour
revidStopTime = 5 * time.Second
prepTime = 20 * time.Second
loggerVerbosity = 3
)
@ -127,7 +126,7 @@ func main() {
// Do we want a netsender session
netSenderFlagPtr := flag.Bool("NetSender", false, "Are we checking vars through netsender?")
// User might also want to define how long revid runs for
runDurationPtr := flag.Int("runDuration", defaultRunDuration, "How long do you want revid to run for?")
runDurationPtr := flag.Duration("runDuration", defaultRunDuration, "How long do you want revid to run for?")
flag.Parse()
@ -246,14 +245,17 @@ func main() {
if *netSenderFlagPtr {
// initialize NetSender and use NetSender's logger
config.Logger = netsender.GetLogger()
ns = netsender.NewNetsender(false, revidReportActions)
// FIXME(kortschak): Handle this error appropriately.
ns, _ = netsender.NewNetsender(false, revidReportActions)
vs = ns.GetVarSum()
} else {
// alternatively, instantiate our own logger
config.Logger = smartlogger.New(loggerVerbosity, smartlogger.File, "/var/log/netsender/")
}
time.Sleep(time.Duration(prepTime) * time.Second)
time.Sleep(prepTime)
startRevid()
paused := false
@ -261,7 +263,7 @@ func main() {
for *netSenderFlagPtr {
if err := netSend(); err != nil {
config.Logger.Log(progName, "Error", err.Error())
time.Sleep(time.Duration(netSendRetryTime) * time.Second)
time.Sleep(netSendRetryTime)
continue
}
@ -270,7 +272,7 @@ func main() {
vars, err := ns.GetVars()
if err != nil {
config.Logger.Log(progName, "Error", err.Error())
time.Sleep(time.Duration(netSendRetryTime) * time.Second)
time.Sleep(netSendRetryTime)
continue
}
vs = ns.GetVarSum()
@ -293,7 +295,7 @@ func main() {
// If we're not running a netsender session then we run revid for the amount
// of time the user defined or the default 2 days
time.Sleep(time.Duration(*runDurationPtr) * time.Second)
time.Sleep(*runDurationPtr)
stopRevid()
}
@ -330,7 +332,7 @@ func stopRevid() {
// FIXME(kortschak): Is this waiting on completion of work?
// Use a wait group and Wait method if it is.
time.Sleep(time.Duration(revidStopTime) * time.Second)
time.Sleep(revidStopTime)
}
func updateRevid(vars map[string]string, stop bool) {