mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
published first event
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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
5
utils/events.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package utils
|
||||
|
||||
const (
|
||||
EVT_ACCOUNT_BALANCE_MODIFIED = "ACCOUNT_BALANCE_MODIFIED"
|
||||
)
|
||||
Reference in New Issue
Block a user