mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-11 03:06:51 +02:00
fixed healthcheck failed to disable and nil dereference
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
type HealthCheckConfig struct {
|
||||
Disabled bool `json:"disabled,omitempty" yaml:"disabled"`
|
||||
Disable bool `json:"disable,omitempty" yaml:"disable"`
|
||||
Path string `json:"path,omitempty" yaml:"path"`
|
||||
UseGet bool `json:"use_get,omitempty" yaml:"use_get"`
|
||||
Interval time.Duration `json:"interval" yaml:"interval"`
|
||||
|
||||
@@ -75,20 +75,25 @@ func (mon *monitor) Start(routeSubtask task.Task) E.NestedError {
|
||||
mon.service = routeSubtask.Parent().Name()
|
||||
mon.task = routeSubtask
|
||||
|
||||
if err := mon.checkUpdateHealth(); err != nil {
|
||||
mon.task.Finish(fmt.Sprintf("healthchecker %s failure: %s", mon.service, err))
|
||||
return err
|
||||
if mon.config.Interval <= 0 {
|
||||
return E.Invalid("interval", mon.config.Interval)
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
monMap.Delete(mon.task.Name())
|
||||
if mon.status.Load() != StatusError {
|
||||
mon.status.Store(StatusUnknown)
|
||||
}
|
||||
mon.task.Finish(mon.task.FinishCause().Error())
|
||||
}()
|
||||
|
||||
if err := mon.checkUpdateHealth(); err != nil {
|
||||
logger.Errorf("healthchecker %s failure: %s", mon.service, err)
|
||||
return
|
||||
}
|
||||
|
||||
monMap.Store(mon.service, mon)
|
||||
defer monMap.Delete(mon.service)
|
||||
|
||||
ticker := time.NewTicker(mon.config.Interval)
|
||||
defer ticker.Stop()
|
||||
|
||||
Reference in New Issue
Block a user