return o zero call costs

This commit is contained in:
Radu Ioan Fericean
2012-07-31 14:51:59 +03:00
parent 2ceb330703
commit eed45bdb0e
4 changed files with 9 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ import (
"log"
"net/rpc"
//"net/rpc/jsonrpc"
"net/rpc/jsonrpc"
"time"
)

View File

@@ -34,7 +34,7 @@ type FSSessionManager struct {
buf *bufio.Reader
sessions []*Session
sessionDelegate *SessionDelegate
postgresLogger *PostgresLogger //NewPostgresLogger("gosqltest", "rif", "testus")
postgresLogger *PostgresLogger
}
func NewFSSessionManager(db *sql.DB) *FSSessionManager {

View File

@@ -36,6 +36,10 @@ func (psl *PostgresLogger) Close() {
}
func (psl *PostgresLogger) Log(uuid string, cc *timespans.CallCost) {
if psl.db == nil {
timespans.Logger.Warning("Cannot write log to database.")
return
}
tss, err := json.Marshal(cc.Timespans)
if err != nil {
log.Printf("Error marshalling timespans to json: %v", err)

View File

@@ -72,6 +72,9 @@ func (rsd *SessionDelegate) OnChannelAnswer(ev Event, s *Session) {
}
func (rsd *SessionDelegate) OnChannelHangupComplete(ev Event, s *Session) {
if len(s.CallCosts) == 0 {
return // why would we have 0 callcosts
}
lastCC := s.CallCosts[len(s.CallCosts)-1]
// put credit back
start := time.Now()