New Action: *publish_account to force publishing account information to ThresholdS, fixes #1059

This commit is contained in:
DanB
2018-04-22 19:50:46 +02:00
parent ef7a32cda1
commit 5bc107fecf
3 changed files with 75 additions and 1 deletions

View File

@@ -81,6 +81,7 @@ const (
CGR_RPC = "*cgr_rpc"
TopUpZeroNegative = "*topup_zero_negative"
SetExpiry = "*set_expiry"
MetaPublishAccount = "*publish_account"
)
func (a *Action) Clone() *Action {
@@ -119,6 +120,7 @@ func getActionFunc(typ string) (actionTypeFunc, bool) {
CGR_RPC: cgrRPCAction,
TopUpZeroNegative: topupZeroNegativeAction,
SetExpiry: setExpiryAction,
MetaPublishAccount: publishAccount,
}
f, exists := actionFuncMap[typ]
return f, exists
@@ -773,6 +775,24 @@ func setExpiryAction(account *Account, sq *CDRStatsQueueTriggered, a *Action, ac
return nil
}
// publishAccount will publish the account as well as each balance received to ThresholdS
func publishAccount(acnt *Account, sq *CDRStatsQueueTriggered,
a *Action, acs Actions) error {
if acnt == nil {
return errors.New("nil account")
}
acnt.Publish()
for bType := range acnt.BalanceMap {
for _, b := range acnt.BalanceMap[bType] {
if b.account == nil {
b.account = acnt
}
b.Publish()
}
}
return nil
}
// Structure to store actions according to weight
type Actions []*Action