mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2025-01-06 10:59:34 +00:00
lint: No err check
This commit is contained in:
parent
062e0e90b1
commit
c25e9224b6
4 changed files with 39 additions and 14 deletions
|
@ -166,21 +166,27 @@ func (p *proberClient) fetchNode(node monero.Node) (monero.Node, error) {
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.message = err.Error()
|
p.message = err.Error()
|
||||||
p.reportResult(node, time.Since(startTime).Seconds())
|
if err := p.reportResult(node, time.Since(startTime).Seconds()); err != nil {
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
return node, err
|
return node, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
p.message = fmt.Sprintf("status code: %d", resp.StatusCode)
|
p.message = fmt.Sprintf("status code: %d", resp.StatusCode)
|
||||||
p.reportResult(node, time.Since(startTime).Seconds())
|
if err := p.reportResult(node, time.Since(startTime).Seconds()); err != nil {
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
return node, errors.New(p.message)
|
return node, errors.New(p.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.message = err.Error()
|
p.message = err.Error()
|
||||||
p.reportResult(node, time.Since(startTime).Seconds())
|
if err := p.reportResult(node, time.Since(startTime).Seconds()); err != nil {
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
return node, err
|
return node, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,9 +196,10 @@ func (p *proberClient) fetchNode(node monero.Node) (monero.Node, error) {
|
||||||
|
|
||||||
if err := json.Unmarshal(body, &reportNode); err != nil {
|
if err := json.Unmarshal(body, &reportNode); err != nil {
|
||||||
p.message = err.Error()
|
p.message = err.Error()
|
||||||
p.reportResult(node, time.Since(startTime).Seconds())
|
if err := p.reportResult(node, time.Since(startTime).Seconds()); err != nil {
|
||||||
return node, err
|
return node, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if reportNode.Status == "OK" {
|
if reportNode.Status == "OK" {
|
||||||
node.IsAvailable = true
|
node.IsAvailable = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package server
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -22,7 +23,10 @@ var probersCmd = &cobra.Command{
|
||||||
This command should only be run on the server which directly connect to the MySQL database.
|
This command should only be run on the server which directly connect to the MySQL database.
|
||||||
`,
|
`,
|
||||||
Run: func(cmd *cobra.Command, _ []string) {
|
Run: func(cmd *cobra.Command, _ []string) {
|
||||||
cmd.Help()
|
if err := cmd.Help(); err != nil {
|
||||||
|
slog.Error(err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,9 @@ func MigrateDb(db *DB) error {
|
||||||
slog.Info(fmt.Sprintf("[DB] Migrating database schema version %d", version+1))
|
slog.Info(fmt.Sprintf("[DB] Migrating database schema version %d", version+1))
|
||||||
|
|
||||||
if err := migrateFn(db); err != nil {
|
if err := migrateFn(db); err != nil {
|
||||||
tx.Rollback()
|
if err := tx.Rollback(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := setSchemaVersion(db, version+1); err != nil {
|
if err := setSchemaVersion(db, version+1); err != nil {
|
||||||
|
@ -52,7 +54,9 @@ func getSchemaVersion(db *DB) int {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
version := 0
|
version := 0
|
||||||
db.Get(&version, `SELECT version FROM tbl_schema_ver`)
|
if err := db.Get(&version, `SELECT version FROM tbl_schema_ver`); err != nil {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"slices"
|
"slices"
|
||||||
|
@ -621,7 +622,9 @@ func (repo *MoneroRepo) ProcessJob(report ProbeReport, proberId int64) error {
|
||||||
WHERE
|
WHERE
|
||||||
node_id = ?
|
node_id = ?
|
||||||
AND date_checked > ?`
|
AND date_checked > ?`
|
||||||
repo.db.Get(&nodeStats, qstats, report.NodeInfo.ID, limitTs)
|
if err := repo.db.Get(&nodeStats, qstats, report.NodeInfo.ID, limitTs); err != nil {
|
||||||
|
slog.Warn(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
avgUptime := (float64(nodeStats.OnlineCount) / float64(nodeStats.TotalFetched)) * 100
|
avgUptime := (float64(nodeStats.OnlineCount) / float64(nodeStats.TotalFetched)) * 100
|
||||||
report.NodeInfo.Uptime = math.Ceil(avgUptime*100) / 100
|
report.NodeInfo.Uptime = math.Ceil(avgUptime*100) / 100
|
||||||
|
@ -684,7 +687,7 @@ func (repo *MoneroRepo) ProcessJob(report ProbeReport, proberId int64) error {
|
||||||
cors_capable = ?
|
cors_capable = ?
|
||||||
WHERE
|
WHERE
|
||||||
id = ?`
|
id = ?`
|
||||||
_, err = repo.db.Exec(update,
|
_, err := repo.db.Exec(update,
|
||||||
nodeAvailable,
|
nodeAvailable,
|
||||||
report.NodeInfo.Nettype,
|
report.NodeInfo.Nettype,
|
||||||
report.NodeInfo.Height,
|
report.NodeInfo.Height,
|
||||||
|
@ -704,8 +707,11 @@ func (repo *MoneroRepo) ProcessJob(report ProbeReport, proberId int64) error {
|
||||||
string(statuesValueToDb),
|
string(statuesValueToDb),
|
||||||
report.NodeInfo.CORSCapable,
|
report.NodeInfo.CORSCapable,
|
||||||
report.NodeInfo.ID)
|
report.NodeInfo.ID)
|
||||||
|
if err != nil {
|
||||||
|
slog.Warn(err.Error())
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
update := `
|
u := `
|
||||||
UPDATE tbl_node
|
UPDATE tbl_node
|
||||||
SET
|
SET
|
||||||
is_available = ?,
|
is_available = ?,
|
||||||
|
@ -714,15 +720,19 @@ func (repo *MoneroRepo) ProcessJob(report ProbeReport, proberId int64) error {
|
||||||
last_check_status = ?
|
last_check_status = ?
|
||||||
WHERE
|
WHERE
|
||||||
id = ?`
|
id = ?`
|
||||||
_, err = repo.db.Exec(update, nodeAvailable, report.NodeInfo.Uptime, now.Unix(), string(statuesValueToDb), report.NodeInfo.ID)
|
if _, err := repo.db.Exec(u, nodeAvailable, report.NodeInfo.Uptime, now.Unix(), string(statuesValueToDb), report.NodeInfo.ID); err != nil {
|
||||||
|
slog.Warn(err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if avgUptime <= 0 && nodeStats.TotalFetched > 300 {
|
if avgUptime <= 0 && nodeStats.TotalFetched > 300 {
|
||||||
fmt.Println("Deleting Monero node (0% uptime from > 300 records)")
|
fmt.Println("Deleting Monero node (0% uptime from > 300 records)")
|
||||||
repo.Delete(report.NodeInfo.ID)
|
if err := repo.Delete(report.NodeInfo.ID); err != nil {
|
||||||
|
slog.Warn(err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.db.Exec(`
|
_, err = repo.db.Exec(`
|
||||||
UPDATE tbl_prober
|
UPDATE tbl_prober
|
||||||
SET last_submit_ts = ?
|
SET last_submit_ts = ?
|
||||||
WHERE id = ?`, now.Unix(), proberId)
|
WHERE id = ?`, now.Unix(), proberId)
|
||||||
|
|
Loading…
Reference in a new issue