37 lines
819 B
Go
37 lines
819 B
Go
package repostatus
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// timeFunction takes a function as an argument and returns the execution time.
|
|
func timeFunction(f func()) time.Duration {
|
|
startTime := time.Now() // Record the start time
|
|
f() // Execute the function
|
|
return time.Since(startTime) // Calculate the elapsed time
|
|
}
|
|
|
|
func (ls *RepoStatus) SetSpeedActual(s string) {
|
|
if !ls.Ready() {
|
|
return
|
|
}
|
|
ls.speedActual.SetValue(s)
|
|
}
|
|
|
|
func (rs *RepoStatus) setSpeed(duration time.Duration) {
|
|
s := fmt.Sprint(duration)
|
|
if rs.speedActual == nil {
|
|
log.Log(WARN, "rs.speedActual == nil")
|
|
return
|
|
}
|
|
rs.speedActual.SetValue(s)
|
|
|
|
if duration > 200*time.Millisecond {
|
|
rs.speed.SetValue("SLOW")
|
|
} else if duration > 50*time.Millisecond {
|
|
rs.speed.SetValue("OK")
|
|
} else {
|
|
rs.speed.SetValue("FAST")
|
|
}
|
|
}
|