mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Implement function to check for service state
This commit is contained in:
committed by
Dan Christian Bogos
parent
17405af987
commit
dcb38c78bf
@@ -101,7 +101,7 @@ func (cS *CacheService) Shutdown() (_ error) {
|
||||
|
||||
// IsRunning returns if the service is running
|
||||
func (cS *CacheService) IsRunning() bool {
|
||||
return true
|
||||
return CheckServiceState(cS.ServiceName(), utils.StateServiceUP, cS.srvIndexer)
|
||||
}
|
||||
|
||||
// ServiceName returns the service name
|
||||
|
||||
@@ -80,7 +80,7 @@ func (s *ConfigService) Shutdown() error {
|
||||
|
||||
// IsRunning returns whether the service is running or not.
|
||||
func (s *ConfigService) IsRunning() bool {
|
||||
return true
|
||||
return CheckServiceState(s.ServiceName(), utils.StateServiceUP, s.srvIndexer)
|
||||
}
|
||||
|
||||
// ServiceName returns the service name
|
||||
|
||||
@@ -74,7 +74,7 @@ func (gv *GlobalVarS) Shutdown() error {
|
||||
|
||||
// IsRunning returns if the service is running
|
||||
func (gv *GlobalVarS) IsRunning() bool {
|
||||
return true
|
||||
return CheckServiceState(gv.ServiceName(), utils.StateServiceUP, gv.srvIndexer)
|
||||
}
|
||||
|
||||
// ServiceName returns the service name
|
||||
|
||||
@@ -80,7 +80,7 @@ func (s *GuardianService) Shutdown() error {
|
||||
|
||||
// IsRunning returns whether the service is running or not.
|
||||
func (s *GuardianService) IsRunning() bool {
|
||||
return true
|
||||
return CheckServiceState(s.ServiceName(), utils.StateServiceUP, s.srvIndexer)
|
||||
}
|
||||
|
||||
// ServiceName returns the service name
|
||||
|
||||
@@ -20,6 +20,8 @@ package services
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/cgrates/cgrates/servmanager"
|
||||
)
|
||||
|
||||
// NewStateDependencies constructs a StateDependencies struct
|
||||
@@ -44,3 +46,12 @@ func (sDs *StateDependencies) StateChan(stateID string) (retChan chan struct{})
|
||||
sDs.stateDepsMux.RUnlock()
|
||||
return
|
||||
}
|
||||
|
||||
func CheckServiceState(id, state string, indexer *servmanager.ServiceIndexer) bool {
|
||||
select {
|
||||
case <-indexer.GetService(id).StateChan(state):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user