From f6f5bdba4e982595ad1c12041d39f75e11792ef8 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 6 Jan 2024 11:12:10 -0600 Subject: stepping through init on a window with state Signed-off-by: Jeff Carr --- linuxstatus/update.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'linuxstatus/update.go') diff --git a/linuxstatus/update.go b/linuxstatus/update.go index 1ab8cee..0de7cf9 100644 --- a/linuxstatus/update.go +++ b/linuxstatus/update.go @@ -1,31 +1,40 @@ package linuxstatus import ( - "errors" "fmt" "time" + "errors" "go.wit.com/log" ) func (ls *LinuxStatus) Update() { - log.Info("linuxStatus() Update() START") - if ls == nil { - log.Error(errors.New("linuxStatus() Update() ls == nil")) + if ! ls.Ready() { + log.Warn("can't update yet. ready is false") + log.Error(errors.New("Update() is not ready yet")) return } + log.Log(INFO, "Update() START") duration := timeFunction(func () { linuxLoop() }) + ls.SetSpeed(duration) + log.Info("linuxStatus() Update() END") +} + +func (ls *LinuxStatus) SetSpeed(duration time.Duration) { s := fmt.Sprint(duration) + if ls.speedActual == nil { + log.Warn("can't actually warn") + return + } ls.speedActual.Set(s) if (duration > 500 * time.Millisecond ) { - // ls.speed, "SLOW") + ls.speed.Set("SLOW") } else if (duration > 100 * time.Millisecond ) { - // ls.speed, "OK") + ls.speed.Set("OK") } else { - // ls.speed, "FAST") + ls.speed.Set("FAST") } - log.Info("linuxStatus() Update() END") } -- cgit v1.2.3