summaryrefslogtreecommitdiff
path: root/update.go
blob: b304370382f958ee86384ee7abaaad1c386184ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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")
	}
}