summaryrefslogtreecommitdiff
path: root/update.go
diff options
context:
space:
mode:
Diffstat (limited to 'update.go')
-rw-r--r--update.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/update.go b/update.go
new file mode 100644
index 0000000..b304370
--- /dev/null
+++ b/update.go
@@ -0,0 +1,40 @@
+package linuxstatus
+
+import (
+ "fmt"
+ "time"
+ "errors"
+
+ "go.wit.com/log"
+)
+
+func (ls *LinuxStatus) Update() {
+ if ! ls.Ready() {
+ log.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.Log(INFO, "Update() END")
+}
+
+func (ls *LinuxStatus) setSpeed(duration time.Duration) {
+ s := fmt.Sprint(duration)
+ if ls.speedActual == nil {
+ log.Log(WARN, "can't actually warn")
+ return
+ }
+ ls.speedActual.Set(s)
+
+ if (duration > 500 * time.Millisecond ) {
+ ls.speed.Set("SLOW")
+ } else if (duration > 100 * time.Millisecond ) {
+ ls.speed.Set("OK")
+ } else {
+ ls.speed.Set("FAST")
+ }
+}