fix: autoupdater log error, if error fetching cpu usage isn't return nil

This commit is contained in:
MedzikUser 2021-08-15 21:17:14 +02:00
parent 3ec66b21b9
commit 7a6103d9f7
2 changed files with 19 additions and 11 deletions

View File

@ -21,20 +21,22 @@ type StatCPU struct {
}
// Get CPU stats
func CPU() (*StatCPU, error) {
func CPU() (StatCPU, error) {
pid := os.Getpid()
sysInfo, err := pidusage.GetStat(pid)
if err != nil {
return nil, err
}
stat := StatCPU{
Usage: fmt.Sprint(math.Round(sysInfo.CPU*100)/100, "%"),
Num: runtime.NumCPU(),
Arch: runtime.GOARCH,
pid: pid,
}
return &stat, nil
sysInfo, err := pidusage.GetStat(pid)
if err != nil {
stat.Usage = "error"
return stat, err
}
stat.Usage = fmt.Sprint(math.Round(sysInfo.CPU*100)/100, "%")
return stat, nil
}

View File

@ -1,6 +1,10 @@
package updater
import "time"
import (
"time"
"github.com/MedzikUser/go-utils/common"
)
/*
Auto checks for available updates
@ -9,7 +13,8 @@ import "time"
*/
func (c *Client) AutoUpdater() {
// Check on start
c.Update()
err := c.Update()
common.CheckErr(err, "AutoUpdater")
ticker := time.NewTicker(c.CheckEvery)
@ -18,7 +23,8 @@ func (c *Client) AutoUpdater() {
for {
select {
case <-ticker.C:
c.Update()
err := c.Update()
common.CheckErr(err, "AutoUpdater")
case <-quit:
ticker.Stop()