Destinations considered from dataDb in case of missing from storDb on load

This commit is contained in:
DanB
2013-11-12 19:30:49 +01:00
parent 64a0cda8c1
commit 13ce865b6f
4 changed files with 28 additions and 7 deletions

View File

@@ -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)
}
}
}
}

View File

@@ -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)

View File

@@ -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)

View File

@@ -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 {