Adding initial stopChan to the engine

This commit is contained in:
DanB
2024-12-01 20:22:47 +01:00
parent 476f5ba877
commit 2dfa1e7035
2 changed files with 9 additions and 3 deletions

View File

@@ -59,7 +59,9 @@ func runCGREngine(fs []string) (err error) {
if cfg, err = services.InitConfigFromPath(ctx, *flags.CfgPath, *flags.NodeID, *flags.LogLevel); err != nil || *flags.CheckConfig {
return
}
cgr := services.NewCGREngine(cfg, servmanager.NewServiceIndexer(), []servmanager.Service{})
stopChan := make(chan struct{})
cgr := services.NewCGREngine(stopChan, cfg, servmanager.NewServiceIndexer(), []servmanager.Service{})
defer cgr.Stop(*flags.PidFile)
if err = cgr.Run(ctx, cancel, flags, vers,
@@ -73,6 +75,7 @@ func runCGREngine(fs []string) (err error) {
}
<-ctx.Done()
//<-stopChan
return
}

View File

@@ -39,12 +39,13 @@ import (
"github.com/cgrates/rpcclient"
)
func NewCGREngine(cfg *config.CGRConfig, sIdxr *servmanager.ServiceIndexer,
func NewCGREngine(stopChan chan struct{}, cfg *config.CGRConfig, sIdxr *servmanager.ServiceIndexer,
services []servmanager.Service) *CGREngine {
cM := engine.NewConnManager(cfg)
caps := engine.NewCaps(cfg.CoreSCfg().Caps, cfg.CoreSCfg().CapsStrategy)
shdWg := new(sync.WaitGroup)
return &CGREngine{
stopChan: stopChan,
cfg: cfg, // Engine configuration
cM: cM,
caps: caps, // caps is used to limit RPC CPS
@@ -93,6 +94,8 @@ func NewCGREngine(cfg *config.CGRConfig, sIdxr *servmanager.ServiceIndexer,
}
type CGREngine struct {
stopChan chan struct{}
cfg *config.CGRConfig
srvManager *servmanager.ServiceManager
@@ -404,7 +407,7 @@ func (cgr *CGREngine) startServices(ctx *context.Context, shtDw context.CancelFu
}
// Run will run the CGREngine, calling it's init and startServices
func (cgr *CGREngine) Run(ctx *context.Context, shtDw context.CancelFunc,
func (cgr *CGREngine) Run(ctx *context.Context, shtDw context.CancelFunc, stopChan chan struct{},
flags *CGREngineFlags, vers string, memProfParams cores.MemoryProfilingParams) (err error) {
if err = cgr.init(ctx, shtDw, flags, vers); err != nil {
return