mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 09:08:45 +05:00
Merge branch 'master' into Diameter2
This commit is contained in:
@@ -1075,26 +1075,35 @@ func (acc *Account) AsAccountSummary() *AccountSummary {
|
||||
}
|
||||
|
||||
func (acnt *Account) Publish() {
|
||||
if thresholdS == nil {
|
||||
return
|
||||
}
|
||||
acntTnt := utils.NewTenantID(acnt.ID)
|
||||
thEv := &ArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: acntTnt.Tenant,
|
||||
ID: utils.GenUUID(),
|
||||
Event: map[string]interface{}{
|
||||
utils.EventType: utils.AccountUpdate,
|
||||
utils.EventSource: utils.AccountService,
|
||||
utils.Account: acntTnt.ID,
|
||||
utils.AllowNegative: acnt.AllowNegative,
|
||||
utils.Disabled: acnt.Disabled}}}
|
||||
var tIDs []string
|
||||
if err := thresholdS.Call(utils.ThresholdSv1ProcessEvent,
|
||||
thEv, &tIDs); err != nil &&
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<AccountS> error: %s processing account event %+v with ThresholdS.", err.Error(), thEv))
|
||||
cgrEv := utils.CGREvent{
|
||||
Tenant: acntTnt.Tenant,
|
||||
ID: utils.GenUUID(),
|
||||
Event: map[string]interface{}{
|
||||
utils.EventType: utils.AccountUpdate,
|
||||
utils.EventSource: utils.AccountService,
|
||||
utils.Account: acntTnt.ID,
|
||||
utils.AllowNegative: acnt.AllowNegative,
|
||||
utils.Disabled: acnt.Disabled}}
|
||||
if statS != nil {
|
||||
var reply []string
|
||||
go func() {
|
||||
if err := statS.Call(utils.StatSv1ProcessEvent, &StatsArgsProcessEvent{CGREvent: cgrEv}, &reply); err != nil &&
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<AccountS> error: %s processing balance event %+v with StatS.",
|
||||
err.Error(), cgrEv))
|
||||
}
|
||||
}()
|
||||
}
|
||||
if thresholdS != nil {
|
||||
var tIDs []string
|
||||
if err := thresholdS.Call(utils.ThresholdSv1ProcessEvent,
|
||||
&ArgsProcessEvent{CGREvent: cgrEv}, &tIDs); err != nil &&
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<AccountS> error: %s processing account event %+v with ThresholdS.", err.Error(), cgrEv))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -696,31 +696,42 @@ func (b *Balance) AsBalanceSummary(typ string) *BalanceSummary {
|
||||
}
|
||||
|
||||
func (b *Balance) Publish() {
|
||||
if b.account == nil ||
|
||||
thresholdS == nil {
|
||||
if b.account == nil {
|
||||
return
|
||||
}
|
||||
accountId := b.account.ID
|
||||
acntTnt := utils.NewTenantID(accountId)
|
||||
thEv := &ArgsProcessEvent{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: acntTnt.Tenant,
|
||||
ID: utils.GenUUID(),
|
||||
Event: map[string]interface{}{
|
||||
utils.EventType: utils.BalanceUpdate,
|
||||
utils.EventSource: utils.AccountService,
|
||||
utils.Account: acntTnt.ID,
|
||||
utils.BalanceID: b.ID,
|
||||
utils.Units: b.Value}}}
|
||||
cgrEv := utils.CGREvent{
|
||||
Tenant: acntTnt.Tenant,
|
||||
ID: utils.GenUUID(),
|
||||
Event: map[string]interface{}{
|
||||
utils.EventType: utils.BalanceUpdate,
|
||||
utils.EventSource: utils.AccountService,
|
||||
utils.Account: acntTnt.ID,
|
||||
utils.BalanceID: b.ID,
|
||||
utils.Units: b.Value}}
|
||||
if !b.ExpirationDate.IsZero() {
|
||||
thEv.Event[utils.ExpiryTime] = b.ExpirationDate.Format(time.RFC3339)
|
||||
cgrEv.Event[utils.ExpiryTime] = b.ExpirationDate.Format(time.RFC3339)
|
||||
}
|
||||
var tIDs []string
|
||||
if err := thresholdS.Call(utils.ThresholdSv1ProcessEvent, thEv, &tIDs); err != nil &&
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<AccountS> error: %s processing balance event %+v with ThresholdS.",
|
||||
err.Error(), thEv))
|
||||
if statS != nil {
|
||||
var reply []string
|
||||
go func() {
|
||||
if err := statS.Call(utils.StatSv1ProcessEvent, &StatsArgsProcessEvent{CGREvent: cgrEv}, &reply); err != nil &&
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<AccountS> error: %s processing balance event %+v with StatS.",
|
||||
err.Error(), cgrEv))
|
||||
}
|
||||
}()
|
||||
}
|
||||
if thresholdS != nil {
|
||||
var tIDs []string
|
||||
if err := thresholdS.Call(utils.ThresholdSv1ProcessEvent, &ArgsProcessEvent{CGREvent: cgrEv}, &tIDs); err != nil &&
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<AccountS> error: %s processing balance event %+v with ThresholdS.",
|
||||
err.Error(), cgrEv))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ var (
|
||||
debitPeriod = 10 * time.Second
|
||||
globalRoundingDecimals = 6
|
||||
thresholdS rpcclient.RpcClientConnection // used by RALs to communicate with ThresholdS
|
||||
statS rpcclient.RpcClientConnection
|
||||
pubSubServer rpcclient.RpcClientConnection
|
||||
userService rpcclient.RpcClientConnection
|
||||
aliasService rpcclient.RpcClientConnection
|
||||
@@ -76,6 +77,10 @@ func SetThresholdS(thdS rpcclient.RpcClientConnection) {
|
||||
thresholdS = thdS
|
||||
}
|
||||
|
||||
func SetStatS(stsS rpcclient.RpcClientConnection) {
|
||||
statS = stsS
|
||||
}
|
||||
|
||||
// Sets the global rounding method and decimal precision for GetCost method
|
||||
func SetRoundingDecimals(rd int) {
|
||||
globalRoundingDecimals = rd
|
||||
|
||||
Reference in New Issue
Block a user