Implement function to check for service state

This commit is contained in:
ionutboangiu
2024-12-18 07:54:37 +02:00
committed by Dan Christian Bogos
parent 17405af987
commit dcb38c78bf
5 changed files with 15 additions and 4 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
}
}