mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 02:26:26 +05:00
Merge branch 'master' of https://github.com/cgrates/cgrates
This commit is contained in:
63
console/balance_debit.go
Normal file
63
console/balance_debit.go
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Rating system designed to be used in VoIP Carriers World
|
||||
Copyright (C) 2012-2015 ITsysCOM
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
import "github.com/cgrates/cgrates/apier/v1"
|
||||
|
||||
func init() {
|
||||
c := &CmdBalanceDebit{
|
||||
name: "balance_debit",
|
||||
rpcMethod: "ApierV1.DebitBalance",
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
}
|
||||
|
||||
// Commander implementation
|
||||
type CmdBalanceDebit struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *v1.AttrAddBalance
|
||||
clientArgs []string
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
func (self *CmdBalanceDebit) Name() string {
|
||||
return self.name
|
||||
}
|
||||
|
||||
func (self *CmdBalanceDebit) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdBalanceDebit) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &v1.AttrAddBalance{}
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdBalanceDebit) PostprocessRpcParams() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdBalanceDebit) RpcResult() interface{} {
|
||||
var s string
|
||||
return &s
|
||||
}
|
||||
@@ -674,10 +674,10 @@ func cgrRPCAction(account *Account, sq *StatsQueueTriggered, a *Action, acs Acti
|
||||
utils.Logger.Err(fmt.Sprintf("error executing *cgr_rpc template %s:", err.Error()))
|
||||
return err
|
||||
}
|
||||
a.ExtraParameters = buf.String()
|
||||
//utils.Logger.Info("ExtraParameters: " + a.ExtraParameters)
|
||||
processedExtraParam := buf.String()
|
||||
//utils.Logger.Info("ExtraParameters: " + parsedExtraParameters)
|
||||
req := RPCRequest{}
|
||||
if err := json.Unmarshal([]byte(a.ExtraParameters), &req); err != nil {
|
||||
if err := json.Unmarshal([]byte(processedExtraParam), &req); err != nil {
|
||||
return err
|
||||
}
|
||||
params, err := utils.GetRpcParams(req.Method)
|
||||
|
||||
@@ -134,6 +134,17 @@ func (sq *StatsQueue) appendQcdr(qcdr *QCdr, runTrigger bool) {
|
||||
stats := sq.getStats()
|
||||
sq.conf.Triggers.Sort()
|
||||
for _, at := range sq.conf.Triggers {
|
||||
// check is effective
|
||||
if at.IsExpired(time.Now()) || !at.IsActive(time.Now()) {
|
||||
continue
|
||||
}
|
||||
|
||||
if at.Executed {
|
||||
// trigger is marked as executed, so skipp it until
|
||||
// the next reset (see RESET_TRIGGERS action type)
|
||||
continue
|
||||
}
|
||||
|
||||
if at.MinQueuedItems > 0 && len(sq.Cdrs) < at.MinQueuedItems {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -202,9 +202,9 @@ func TestStatsQueueIds(t *testing.T) {
|
||||
t.Error("Errorf getting queue ids: ", err)
|
||||
}
|
||||
result := len(ids)
|
||||
expected := 2
|
||||
expected := 5
|
||||
if result != expected {
|
||||
t.Errorf("Errorf loading stats queues. Expected %v was %v", expected, result)
|
||||
t.Errorf("Errorf loading stats queues. Expected %v was %v (%v)", expected, result, ids)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ func TestStatsAppendCdr(t *testing.T) {
|
||||
t.Error("Error appending cdr to stats: ", err)
|
||||
}
|
||||
t.Log(cdrStats.queues)
|
||||
if len(cdrStats.queues) != 2 ||
|
||||
if len(cdrStats.queues) != 5 ||
|
||||
len(cdrStats.queues["CDRST1"].Cdrs) != 0 ||
|
||||
len(cdrStats.queues["CDRST2"].Cdrs) != 1 {
|
||||
t.Error("Error appending cdr to queue: ", utils.ToIJSON(cdrStats.queues))
|
||||
@@ -280,7 +280,7 @@ func TestStatsReloadQueues(t *testing.T) {
|
||||
t.Error("Error getting queue ids: ", err)
|
||||
}
|
||||
result := len(ids)
|
||||
expected := 2
|
||||
expected := 5
|
||||
if result != expected {
|
||||
t.Errorf("Error loading stats queues. Expected %v was %v: %v", expected, result, ids)
|
||||
}
|
||||
@@ -316,7 +316,7 @@ func TestStatsReloadQueuesWithDefault(t *testing.T) {
|
||||
t.Error("Error getting queue ids: ", err)
|
||||
}
|
||||
result := len(ids)
|
||||
expected := 2
|
||||
expected := 6
|
||||
if result != expected {
|
||||
t.Errorf("Error loading stats queues. Expected %v was %v", expected, result)
|
||||
}
|
||||
@@ -348,7 +348,7 @@ func TestStatsReloadQueuesWithIds(t *testing.T) {
|
||||
t.Error("Error getting queue ids: ", err)
|
||||
}
|
||||
result := len(ids)
|
||||
expected := 2
|
||||
expected := 6
|
||||
if result != expected {
|
||||
t.Errorf("Error loading stats queues. Expected %v was %v", expected, result)
|
||||
}
|
||||
@@ -398,7 +398,7 @@ func TestStatsResetQueues(t *testing.T) {
|
||||
t.Error("Error getting queue ids: ", err)
|
||||
}
|
||||
result := len(ids)
|
||||
expected := 2
|
||||
expected := 6
|
||||
if result != expected {
|
||||
t.Errorf("Error loading stats queues. Expected %v was %v", expected, result)
|
||||
}
|
||||
@@ -430,7 +430,7 @@ func TestStatsResetQueuesWithIds(t *testing.T) {
|
||||
t.Error("Error getting queue ids: ", err)
|
||||
}
|
||||
result := len(ids)
|
||||
expected := 2
|
||||
expected := 6
|
||||
if result != expected {
|
||||
t.Errorf("Error loading stats queues. Expected %v was %v", expected, result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user