diff --git a/apier/tpdestinations.go b/apier/tpdestinations.go index 115e02834..1f8f47d50 100644 --- a/apier/tpdestinations.go +++ b/apier/tpdestinations.go @@ -57,55 +57,56 @@ func (self *Apier) GetDestination(tag string, reply *rater.Destination) error { func (self *Apier) SetDestination(dest *rater.Destination, reply *rater.Destination) error { if err := self.StorDb.SetDestination(dest); err != nil { return err - } + } return nil } -/* -func (self *Apier) GetMoneyBalance(arg CallDescriptor, reply *CallCost) (err error) { - err = rs.getBalance(&arg, CREDIT, reply) +type AttrBalance struct { + Account string + Direction string +} + +func (self *Apier) GetMoneyBalance(attr *AttrBalance, reply *float64) (err error) { + err = self.getBalance(attr, rater.CREDIT, reply) return err } -func (self *Apier) GetSMSBalance(arg CallDescriptor, reply *CallCost) (err error) { - err = rs.getBalance(&arg, SMS, reply) +func (self *Apier) GetSMSBalance(attr *AttrBalance, reply *float64) (err error) { + err = self.getBalance(attr, rater.SMS, reply) return err } -func (self *Apier) GetInternetBalance(arg CallDescriptor, reply *CallCost) (err error) { - err = rs.getBalance(&arg, TRAFFIC, reply) +func (self *Apier) GetInternetBalance(attr *AttrBalance, reply *float64) (err error) { + err = self.getBalance(attr, rater.TRAFFIC, reply) return err } -func (self *Apier) GetInternetTimeBalance(arg CallDescriptor, reply *CallCost) (err error) { - err = rs.getBalance(&arg, TRAFFIC_TIME, reply) +func (self *Apier) GetInternetTimeBalance(attr *AttrBalance, reply *float64) (err error) { + err = self.getBalance(attr, rater.TRAFFIC_TIME, reply) return err } -func (self *Apier) GetMinutesBalance(arg CallDescriptor, reply *CallCost) (err error) { - err = rs.getBalance(&arg, MINUTES, reply) +func (self *Apier) GetMinutesBalance(attr *AttrBalance, reply *float64) (err error) { + err = self.getBalance(attr, rater.MINUTES, reply) return err } // Get balance -func (rs *Responder) getBalance(arg *CallDescriptor, balanceId string, reply *CallCost) (err error) { - if rs.Bal != nil { - return errors.New("No balancer supported for this command right now") - } - ubKey := arg.Direction + ":" + arg.Tenant + ":" + arg.Account - userBalance, err := storageGetter.GetUserBalance(ubKey) +func (self *Apier) getBalance(attr *AttrBalance, balanceId string, reply *float64) (err error) { + userBalance, err := self.StorDb.GetUserBalance(attr.Account) if err != nil { return err } - if balance, balExists := userBalance.BalanceMap[balanceId+arg.Direction]; !balExists { + if balance, balExists := userBalance.BalanceMap[balanceId+attr.Direction]; !balExists { // No match, balanceId not found - return errors.New("-BALANCE_NOT_FOUND") + return errors.New(utils.ERR_NOT_FOUND) } else { - reply.Tenant = arg.Tenant - reply.Account = arg.Account - reply.Direction = arg.Direction - reply.Cost = balance + *reply = balance } return nil } -*/ \ No newline at end of file + +func (self *Apier) AddTimedAction(attr *AttrBalance, reply *float64) (err error) { + err = self.getBalance(attr, rater.MINUTES, reply) + return err +} diff --git a/rater/action_timing.go b/rater/action_timing.go index d4a3ebf63..3e9c83843 100644 --- a/rater/action_timing.go +++ b/rater/action_timing.go @@ -40,8 +40,8 @@ type ActionTiming struct { Weight float64 ActionsId string actions Actions - stCache time.Time - actionsTag, timingsTag string // used only for loading + stCache time.Time // cached time of the next start + actionsTag, timingsTag string // used only for loading } type ActionTimings []*ActionTiming @@ -235,8 +235,8 @@ func (at *ActionTiming) Execute() (err error) { // returns true if the *asap string was found func (at *ActionTiming) CheckForASAP() bool { if at.Timing.StartTime == ASAP { - oneMinute, _ := time.ParseDuration(ASAP_DELAY) - timeTokens := strings.Split(time.Now().Add(oneMinute).Format(time.Stamp), " ") + delay, _ := time.ParseDuration(ASAP_DELAY) + timeTokens := strings.Split(time.Now().Add(delay).Format(time.Stamp), " ") at.Timing.StartTime = timeTokens[len(timeTokens)-1] return true } diff --git a/rater/rater.test b/rater/rater.test deleted file mode 100755 index 050e3568c..000000000 Binary files a/rater/rater.test and /dev/null differ diff --git a/rater/userbalance.go b/rater/userbalance.go index d86a2b385..332d8360a 100644 --- a/rater/userbalance.go +++ b/rater/userbalance.go @@ -44,12 +44,12 @@ const ( Structure containing information about user's credit (minutes, cents, sms...).' */ type UserBalance struct { - Id string - Type string // prepaid-postpaid - BalanceMap map[string]float64 - MinuteBuckets []*MinuteBucket - UnitCounters []*UnitsCounter - ActionTriggers ActionTriggerPriotityList + Id string + Type string // prepaid-postpaid + BalanceMap map[string]float64 + MinuteBuckets []*MinuteBucket + UnitCounters []*UnitsCounter + ActionTriggers ActionTriggerPriotityList } /* diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index 492a28f9a..967a3d23b 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -73,7 +73,7 @@ func (s *Scheduler) LoadActionTimings(storage rater.DataStorage) { for key, ats := range actionTimings { toBeSaved := false isAsap := false - newAts := make([]*rater.ActionTiming, 0) + newAts := make([]*rater.ActionTiming, 0) // will remove the one time runs from the database for _, at := range ats { isAsap = at.CheckForASAP() toBeSaved = toBeSaved || isAsap diff --git a/utils/consts.go b/utils/consts.go index 5ffd2d0a1..cf1689f09 100644 --- a/utils/consts.go +++ b/utils/consts.go @@ -1,17 +1,16 @@ package utils const ( - LOCALHOST = "127.0.0.1" - FSCDR_FILE_CSV = "freeswitch_file_csv" - FSCDR_HTTP_JSON = "freeswitch_http_json" - NOT_IMPLEMENTED = "not implemented" - PREPAID = "prepaid" - POSTPAID = "postpaid" - PSEUDOPREPAID = "pseudoprepaid" - RATED = "rated" - ERR_NOT_IMPLEMENTED = "NOT_IMPLEMENTED" - ERR_SERVER_ERROR = "SERVER_ERROR" - ERR_NOT_FOUND = "NOT_FOUND" + LOCALHOST = "127.0.0.1" + FSCDR_FILE_CSV = "freeswitch_file_csv" + FSCDR_HTTP_JSON = "freeswitch_http_json" + NOT_IMPLEMENTED = "not implemented" + PREPAID = "prepaid" + POSTPAID = "postpaid" + PSEUDOPREPAID = "pseudoprepaid" + RATED = "rated" + ERR_NOT_IMPLEMENTED = "NOT_IMPLEMENTED" + ERR_SERVER_ERROR = "SERVER_ERROR" + ERR_NOT_FOUND = "NOT_FOUND" ERR_MANDATORY_IE_MISSING = "MANDATORY_IE_MISSING" ) -