mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-24 00:28:44 +05:00
Suppliers *least_cost ignoring suppliers with empty cost information
This commit is contained in:
@@ -44,10 +44,10 @@ var sTestsSupplierSV1 = []func(t *testing.T){
|
||||
testV1SplSLoadConfig,
|
||||
testV1SplSInitDataDb,
|
||||
testV1SplSResetStorDb,
|
||||
//testV1SplSStartEngine,
|
||||
testV1SplSStartEngine,
|
||||
testV1SplSRpcConn,
|
||||
testV1SplSFromFolder,
|
||||
//testV1SplSGetWeightSuppliers,
|
||||
testV1SplSGetWeightSuppliers,
|
||||
testV1SplSGetLeastCostSuppliers,
|
||||
testV1SplSStopEngine,
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
@@ -37,17 +39,22 @@ func (lcs *LeastCostSorter) SortSuppliers(prflID string,
|
||||
suppls []*Supplier, ev *SupplierEvent) (sortedSuppls *SortedSuppliers, err error) {
|
||||
sortedSuppls = &SortedSuppliers{ProfileID: prflID,
|
||||
Sorting: lcs.sorting,
|
||||
SortedSuppliers: make([]*SortedSupplier, len(suppls))}
|
||||
for i, s := range suppls {
|
||||
SortedSuppliers: make([]*SortedSupplier, 0)}
|
||||
for _, s := range suppls {
|
||||
ec, err := lcs.spS.costForEvent(ev, s.AccountIDs, s.RatingPlanIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if ec == nil {
|
||||
utils.Logger.Warning(
|
||||
fmt.Sprintf("<%s> profile: %s ignoring supplier with ID: %s, missing cost information",
|
||||
utils.SupplierS, prflID, s.ID))
|
||||
continue
|
||||
}
|
||||
sortedSuppls.SortedSuppliers[i] = &SortedSupplier{
|
||||
sortedSuppls.SortedSuppliers = append(sortedSuppls.SortedSuppliers, &SortedSupplier{
|
||||
SupplierID: s.ID,
|
||||
SortingData: map[string]interface{}{
|
||||
utils.Weight: s.Weight,
|
||||
utils.Cost: ec.GetCost()}}
|
||||
utils.Cost: ec.GetCost()}})
|
||||
}
|
||||
sortedSuppls.SortCost()
|
||||
return
|
||||
|
||||
@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
@@ -229,7 +228,7 @@ func (spS *SupplierService) costForEvent(ev *SupplierEvent,
|
||||
}
|
||||
return NewEventCostFromCallCost(cc, "", ""), nil
|
||||
}
|
||||
return nil, errors.New("no cost found")
|
||||
return
|
||||
}
|
||||
|
||||
// statMetrics will query a list of statIDs and return composed metric values
|
||||
|
||||
Reference in New Issue
Block a user