mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 09:08:45 +05:00
Destinations considered from dataDb in case of missing from storDb on load
This commit is contained in:
@@ -167,7 +167,11 @@ func (dbr *DbReader) LoadDestinationRates() (err error) {
|
||||
}
|
||||
}
|
||||
if !destinationExists {
|
||||
return errors.New(fmt.Sprintf("Could not get destination for tag %v", dr.DestinationsTag))
|
||||
if dbExists, err := dbr.dataDb.ExistsDestination(dr.DestinationsTag); err != nil {
|
||||
return err
|
||||
} else if !dbExists {
|
||||
return errors.New(fmt.Sprintf("Could not get destination for tag %v", dr.DestinationsTag))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -280,13 +284,20 @@ func (dbr *DbReader) LoadRatingProfileByTag(tag string) error {
|
||||
}
|
||||
resultRatingProfile.RatingPlanActivations = append(resultRatingProfile.RatingPlanActivations, &RatingPlanActivation{at, ratingProfile.DestRatesTimingTag})
|
||||
dms, err := dbr.storDb.GetTpDestinations(dbr.tpid, drate.DestinationsTag)
|
||||
if err != nil || len(dms) == 0 {
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not get destination id %s: %v", drate.DestinationsTag, err)
|
||||
}
|
||||
Logger.Debug(fmt.Sprintf("Tag: %s Destinations: %v", drate.DestinationsTag, dms))
|
||||
for _, destination := range dms {
|
||||
Logger.Debug(fmt.Sprintf("Destination: %v", rpm))
|
||||
dbr.dataDb.SetDestination(destination)
|
||||
} else if len(dms) == 0 {
|
||||
if dbExists, err := dbr.dataDb.ExistsDestination(drate.DestinationsTag); err != nil {
|
||||
return err
|
||||
} else if !dbExists {
|
||||
return fmt.Errorf("Could not get destination for tag %v", drate.DestinationsTag)
|
||||
}
|
||||
} else {
|
||||
Logger.Debug(fmt.Sprintf("Tag: %s Destinations: %v", drate.DestinationsTag, dms))
|
||||
for _, destination := range dms {
|
||||
Logger.Debug(fmt.Sprintf("Destination: %v", rpm))
|
||||
dbr.dataDb.SetDestination(destination)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ type DataStorage interface {
|
||||
GetDestination(string) (*Destination, error)
|
||||
// DestinationContainsPrefix(string, string) (int, error)
|
||||
SetDestination(*Destination) error
|
||||
ExistsDestination(string) (bool, error)
|
||||
GetActions(string) (Actions, error)
|
||||
SetActions(string, Actions) error
|
||||
GetUserBalance(string) (*UserBalance, error)
|
||||
|
||||
@@ -142,6 +142,11 @@ func (ms *MapStorage) SetDestination(dest *Destination) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) ExistsDestination(destId string) (bool, error) {
|
||||
_, exists := ms.dict[DESTINATION_PREFIX+destId]
|
||||
return exists, nil
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetActions(key string) (as Actions, err error) {
|
||||
if values, ok := ms.dict[ACTION_PREFIX+key]; ok {
|
||||
err = ms.ms.Unmarshal(values, &as)
|
||||
|
||||
@@ -219,6 +219,10 @@ func (rs *RedisStorage) SetDestination(dest *Destination) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) ExistsDestination(destId string) (bool, error) {
|
||||
return rs.db.Exists(DESTINATION_PREFIX+destId)
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetActions(key string) (as Actions, err error) {
|
||||
var values string
|
||||
if values, err = rs.db.Get(ACTION_PREFIX + key); err == nil {
|
||||
|
||||
Reference in New Issue
Block a user