From 41eb46c702ab0301cd504826d9d69e327aa0dd0a Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Fri, 8 Jun 2018 21:52:11 +0930 Subject: [PATCH] cmd/revid-cli: use time.Duration for durations --- cmd/revid-cli/main.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 2385a3a1..5a709193 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -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) {