From 9fbc88a60f77450376c69828149b202f570015b8 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Fri, 20 Sep 2019 17:55:02 +0100 Subject: [PATCH] Provide a way to get status now --- monitor/default.go | 16 ++++++++++++++++ monitor/monitor.go | 2 ++ 2 files changed, 18 insertions(+) diff --git a/monitor/default.go b/monitor/default.go index 9455f25c..a03a0b31 100644 --- a/monitor/default.go +++ b/monitor/default.go @@ -24,6 +24,22 @@ type monitor struct { services map[string]*Status } +func (m *monitor) Check(service string) error { + status, err := m.check(service) + if err != nil { + return err + } + m.Lock() + m.services[service] = status + m.Unlock() + + if status.Code != StatusRunning { + return errors.New(status.Info) + } + + return nil +} + // check provides binary running/failed status. // In the event Debug.Health cannot be called on a service we reap the node. func (m *monitor) check(service string) (*Status, error) { diff --git a/monitor/monitor.go b/monitor/monitor.go index 711d7d03..c5f5033d 100644 --- a/monitor/monitor.go +++ b/monitor/monitor.go @@ -17,6 +17,8 @@ type StatusCode int type Monitor interface { // Reap a service and stop monitoring Reap(service string) error + // Check the status of the service now + Check(service string) error // Status of the service Status(service string) (Status, error) // Watch starts watching the service