mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Updated services shutdown
This commit is contained in:
committed by
Dan Christian Bogos
parent
65b03bbdc4
commit
a81fce8341
@@ -82,15 +82,14 @@ func (aS *AnalyzerService) deleteHits(hits search.DocumentMatchCollection) (err
|
||||
}
|
||||
|
||||
// ListenAndServe will initialize the service
|
||||
func (aS *AnalyzerService) ListenAndServe(exitChan chan bool) (err error) {
|
||||
func (aS *AnalyzerService) ListenAndServe(exitChan <-chan struct{}) (err error) {
|
||||
utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.AnalyzerS))
|
||||
if err = aS.clenaUp(); err != nil { // clean up the data at the system start
|
||||
return
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case e := <-exitChan:
|
||||
exitChan <- e // put back for the others listening for shutdown request
|
||||
case <-exitChan:
|
||||
return
|
||||
case <-time.After(aS.cfg.AnalyzerSCfg().CleanupInterval):
|
||||
if err = aS.clenaUp(); err != nil {
|
||||
|
||||
@@ -57,8 +57,8 @@ func TestNewAnalyzerService(t *testing.T) {
|
||||
if err = anz.initDB(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
exitChan := make(chan bool, 1)
|
||||
exitChan <- true
|
||||
exitChan := make(chan struct{}, 1)
|
||||
exitChan <- struct{}{}
|
||||
if err := anz.ListenAndServe(exitChan); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -169,7 +169,7 @@ func TestAnalyzersListenAndServe(t *testing.T) {
|
||||
if err := anz.db.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
anz.ListenAndServe(make(chan bool))
|
||||
anz.ListenAndServe(make(chan struct{}))
|
||||
|
||||
cfg.AnalyzerSCfg().CleanupInterval = 1
|
||||
anz, err = NewAnalyzerService(cfg)
|
||||
@@ -181,7 +181,7 @@ func TestAnalyzersListenAndServe(t *testing.T) {
|
||||
runtime.Gosched()
|
||||
anz.db.Close()
|
||||
}()
|
||||
anz.ListenAndServe(make(chan bool))
|
||||
anz.ListenAndServe(make(chan struct{}))
|
||||
if err := os.RemoveAll(cfg.AnalyzerSCfg().DBPath); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user