published first event

This commit is contained in:
Radu Ioan Fericean
2015-07-03 20:21:07 +03:00
parent 5adc94a45f
commit a3e2526c42
4 changed files with 32 additions and 1 deletions

View File

@@ -22,6 +22,7 @@ import (
"errors"
"fmt"
"sort"
"strconv"
"strings"
"time"
@@ -280,6 +281,24 @@ func (b *Balance) GetCost(cd *CallDescriptor, getStandardIfEmpty bool) (*CallCos
}
func (b *Balance) SubstractAmount(amount float64) {
accountId := ""
if b.account != nil {
accountId = b.account.Id
}
Publish(CgrEvent{
"EventName": utils.EVT_ACCOUNT_BALANCE_MODIFIED,
"Uuid": b.Uuid,
"Id": b.Id,
"Value": strconv.FormatFloat(b.Value, 'f', -1, 64),
"ExpirationDate": b.ExpirationDate.String(),
"Weight": strconv.FormatFloat(b.Weight, 'f', -1, 64),
"DestinationIds": b.DestinationIds,
"RatingSubject": b.RatingSubject,
"Category": b.Category,
"SharedGroup": b.SharedGroup,
"TimingIDs": b.TimingIDs,
"Account": accountId,
})
b.Value -= amount
b.Value = utils.Round(b.Value, globalRoundingDecimals, utils.ROUNDING_MIDDLE)
b.dirty = true

View File

@@ -108,6 +108,13 @@ func SetPubSub(ps PublisherSubscriber) {
pubSubServer = ps
}
func Publish(event CgrEvent) {
if pubSubServer != nil {
var s string
pubSubServer.Publish(PublishInfo{Event: event}, &s)
}
}
/*
The input stucture that contains call information.
*/

View File

@@ -132,7 +132,7 @@ func (ps *PubSub) Publish(pi PublishInfo, reply *string) error {
ps.removeSubscriber(key)
continue // subscription expired, do not send event
}
if !pi.Event.PassFilters(subData.Filters) {
if subData.Filters == nil || !pi.Event.PassFilters(subData.Filters) {
continue // the event does not match the filters
}
split := utils.InfieldSplit(key)

5
utils/events.go Normal file
View File

@@ -0,0 +1,5 @@
package utils
const (
EVT_ACCOUNT_BALANCE_MODIFIED = "ACCOUNT_BALANCE_MODIFIED"
)