mirror of
https://github.com/bakito/adguardhome-sync.git
synced 2025-09-29 17:44:25 +08:00
fix: Correct version check and refactor healthz check
This commit is contained in:
parent
447bfb24a9
commit
7b382ada9f
2 changed files with 16 additions and 25 deletions
|
@ -94,7 +94,21 @@ func (w *worker) handleStatus(c *gin.Context) {
|
|||
}
|
||||
|
||||
func (w *worker) handleHealthz(c *gin.Context) {
|
||||
c.Status(w.healthz())
|
||||
status := w.status()
|
||||
|
||||
if status.Origin.Status != "success" {
|
||||
c.Status(http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
|
||||
for _, replica := range status.Replicas {
|
||||
if replica.Status != "success" {
|
||||
c.Status(http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
func (w *worker) listenAndServe() {
|
||||
|
|
|
@ -3,7 +3,6 @@ package sync
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"sort"
|
||||
"time"
|
||||
|
@ -21,10 +20,7 @@ import (
|
|||
"github.com/bakito/adguardhome-sync/version"
|
||||
)
|
||||
|
||||
var (
|
||||
l = log.GetLogger("sync")
|
||||
fixVersionCompareRegExp = regexp.MustCompile(`[^0-9.]`)
|
||||
)
|
||||
var l = log.GetLogger("sync")
|
||||
|
||||
// Sync config from origin to replica.
|
||||
func Sync(cfg *types.Config) error {
|
||||
|
@ -124,22 +120,6 @@ func (w *worker) status() *syncStatus {
|
|||
return syncStatus
|
||||
}
|
||||
|
||||
func (w *worker) healthz() int {
|
||||
status := w.status()
|
||||
|
||||
if status.Origin.Status != "success" {
|
||||
return 503
|
||||
}
|
||||
|
||||
for _, replica := range status.Replicas {
|
||||
if replica.Status != "success" {
|
||||
return 503
|
||||
}
|
||||
}
|
||||
|
||||
return 200
|
||||
}
|
||||
|
||||
func (w *worker) getStatus(inst types.AdGuardInstance) replicaStatus {
|
||||
st := replicaStatus{Host: inst.WebHost, URL: inst.WebURL}
|
||||
|
||||
|
@ -313,9 +293,6 @@ func (w *worker) syncTo(l *zap.SugaredLogger, o *origin, replica types.AdGuardIn
|
|||
return
|
||||
}
|
||||
|
||||
replicaStatus.Version = fixVersionCompareRegExp.ReplaceAllString(replicaStatus.Version, "")
|
||||
o.status.Version = fixVersionCompareRegExp.ReplaceAllString(o.status.Version, "")
|
||||
|
||||
rl.With("version", replicaStatus.Version).Info("Connected to replica")
|
||||
|
||||
if versions.IsNewerThan(versions.MinAgh, replicaStatus.Version) {
|
||||
|
|
Loading…
Add table
Reference in a new issue