BUG fixup on calls which were started previous to CGRateS start

This commit is contained in:
DanB
2013-04-10 14:37:48 +02:00
parent e6ac3897d4
commit 44d5ef8854
2 changed files with 18 additions and 11 deletions

View File

@@ -186,19 +186,14 @@ func (sm *FSSessionManager) OnChannelAnswer(ev Event) {
if s != nil {
sm.sessions = append(sm.sessions, s)
}
// Make sure cgr_type is enforced even if not set by FreeSWITCH
cgrType := ev.GetReqType()
if cgrType != "" {
err := fsock.FS.SendApiCmd(fmt.Sprintf("uuid_setvar %s cgr_type %s\n\n", s.uuid, cgrType))
if err != nil {
rater.Logger.Err("<SessionManager> Could not enforce cgr_type variable on FreeSWITCH uuid")
}
}
}
func (sm *FSSessionManager) OnChannelHangupComplete(ev Event) {
rater.Logger.Info("<SessionManager> FreeSWITCH hangup.")
s := sm.GetSession(ev.GetUUID())
if s == nil { // Not handled by us
return
}
sm.RemoveSession(s) // Session cleanup from memory
if ev.GetReqType() == REQTYPE_POSTPAID {
startTime, err := ev.GetStartTime(START_TIME)
@@ -345,10 +340,17 @@ func (sm *FSSessionManager) Shutdown() (err error) {
return errors.New("Cannot shutdown sessions, fsock not connected")
}
rater.Logger.Info("Shutting down all sessions...")
fsock.FS.SendApiCmd("hupall MANAGER_REQUEST cgr_reqtype prepaid")
cmdKillPrepaid := "hupall MANAGER_REQUEST cgr_reqtype prepaid"
cmdKillPostpaid := "hupall MANAGER_REQUEST cgr_reqtype postpaid"
for _,cmd := range[]string{cmdKillPrepaid, cmdKillPostpaid} {
if err = fsock.FS.SendApiCmd(cmd); err!= nil {
rater.Logger.Err(fmt.Sprintf("Error on calls shutdown: %s", err))
return
}
}
for guard := 0; len(sm.sessions) > 0 && guard < 20; guard++ {
time.Sleep(100 * time.Millisecond) // wait for the hungup event to be fired
rater.Logger.Info(fmt.Sprintf("<SessionManager> Shutdown waiting on sessions: %s", sm.sessions))
rater.Logger.Info(fmt.Sprintf("<SessionManager> Shutdown waiting on sessions: %v", sm.sessions))
}
return
}

View File

@@ -21,6 +21,7 @@ package sessionmanager
import (
"fmt"
"github.com/cgrates/cgrates/rater"
"github.com/cgrates/fsock"
"strings"
"time"
)
@@ -37,10 +38,14 @@ type Session struct {
// Creates a new session and starts the debit loop
func NewSession(ev Event, sm SessionManager) (s *Session) {
// if there is no account configured leave the call alone
// Ignore calls which have nothing to do with CGRateS
if strings.TrimSpace(ev.GetReqType()) == "" {
return
}
// Make sure cgr_type is enforced even if not set by FreeSWITCH
if err := fsock.FS.SendApiCmd(fmt.Sprintf("uuid_setvar %s cgr_reqtype %s\n\n", ev.GetUUID(), ev.GetReqType())); err!=nil {
rater.Logger.Err(fmt.Sprintf("Error on attempting to overwrite cgr_type in chan variables: %v", err))
}
startTime, err := ev.GetStartTime(START_TIME)
if err != nil {
rater.Logger.Err("Error parsing answer event start time, using time.Now!")