mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-22 23:58:44 +05:00
user budget sone and redis back on speed
This commit is contained in:
@@ -19,12 +19,14 @@ var (
|
||||
apfile = flag.String("apfile", "ap.json", "Activation Periods containing intervals file")
|
||||
destfile = flag.String("destfile", "dest.json", "Destinations file")
|
||||
tpfile = flag.String("tpfile", "tp.json", "Tariff plans file")
|
||||
ubfile = flag.String("ubfile", "ub.json", "User budgets file")
|
||||
)
|
||||
|
||||
func writeToStorage(storage timespans.StorageGetter,
|
||||
callDescriptors []*timespans.CallDescriptor,
|
||||
destinations []*timespans.Destination,
|
||||
tariffPlans []*timespans.TariffPlan) {
|
||||
tariffPlans []*timespans.TariffPlan,
|
||||
userBudgets []*timespans.UserBudget) {
|
||||
for _, cd := range callDescriptors {
|
||||
storage.SetActivationPeriods(cd.GetKey(), cd.ActivationPeriods)
|
||||
log.Printf("Storing %q", cd.GetKey())
|
||||
@@ -37,6 +39,10 @@ func writeToStorage(storage timespans.StorageGetter,
|
||||
storage.SetTariffPlan(tp)
|
||||
log.Printf("Storing %q", tp.Id)
|
||||
}
|
||||
for _, ub := range userBudgets {
|
||||
storage.SetUserBudget(ub)
|
||||
log.Printf("Storing %q", ub.Id)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -92,19 +98,35 @@ func main() {
|
||||
}
|
||||
fin.Close()
|
||||
|
||||
// reading user budgets
|
||||
fin, err = os.Open(*ubfile)
|
||||
|
||||
if err != nil {
|
||||
log.Print("Cannot open user budgets input file", err)
|
||||
}
|
||||
|
||||
dec = json.NewDecoder(fin)
|
||||
|
||||
var userBudgets []*timespans.UserBudget
|
||||
if err := dec.Decode(&userBudgets); err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
fin.Close()
|
||||
|
||||
switch *storage {
|
||||
case "kyoto":
|
||||
storage, _ := timespans.NewKyotoStorage(*kyotofile)
|
||||
defer storage.Close()
|
||||
writeToStorage(storage, callDescriptors, destinations, tariffPlans)
|
||||
writeToStorage(storage, callDescriptors, destinations, tariffPlans, userBudgets)
|
||||
case "mongo":
|
||||
storage, _ := timespans.NewMongoStorage("127.0.0.1", "test")
|
||||
defer storage.Close()
|
||||
writeToStorage(storage, callDescriptors, destinations, tariffPlans)
|
||||
writeToStorage(storage, callDescriptors, destinations, tariffPlans, userBudgets)
|
||||
|
||||
default:
|
||||
storage, _ := timespans.NewRedisStorage(*redisserver, *redisdb)
|
||||
defer storage.Close()
|
||||
writeToStorage(storage, callDescriptors, destinations, tariffPlans)
|
||||
writeToStorage(storage, callDescriptors, destinations, tariffPlans, userBudgets)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user