mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 21:29:52 +05:00
writing the loaded rating profile to db
This commit is contained in:
@@ -140,11 +140,11 @@ func main() {
|
||||
}
|
||||
}
|
||||
//sep = []rune(*separator)[0]
|
||||
loader = rater.NewFileCSVReader(',', destinationsFn, ratesFn, timingsFn, ratetimingsFn, ratingprofilesFn, actionsFn, actiontimingsFn, actiontriggersFn, accountactionsFn)
|
||||
loader = rater.NewFileCSVReader(getter, ',', destinationsFn, ratesFn, timingsFn, ratetimingsFn, ratingprofilesFn, actionsFn, actiontimingsFn, actiontriggersFn, accountactionsFn)
|
||||
}
|
||||
|
||||
if *dataDbId != "" {
|
||||
loader = rater.NewDbReader(getter, *dataDbId)
|
||||
loader = rater.NewDbReader(getter, getter, *dataDbId)
|
||||
}
|
||||
|
||||
err = loader.LoadDestinations()
|
||||
@@ -185,7 +185,7 @@ func main() {
|
||||
}
|
||||
|
||||
// write maps to database
|
||||
if err := loader.WriteToDatabase(getter, *flush, true); err != nil {
|
||||
if err := loader.WriteToDatabase(*flush, true); err != nil {
|
||||
log.Fatal("Could not write to database: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
|
||||
type CSVReader struct {
|
||||
sep rune
|
||||
storage DataStorage
|
||||
readerFunc func(string, rune) (*csv.Reader, *os.File, error)
|
||||
actions map[string][]*Action
|
||||
actionsTimings map[string][]*ActionTiming
|
||||
@@ -47,9 +48,10 @@ type CSVReader struct {
|
||||
actionsFn, actiontimingsFn, actiontriggersFn, accountactionsFn string
|
||||
}
|
||||
|
||||
func NewFileCSVReader(sep rune, destinationsFn, ratesFn, timingsFn, ratetimingsFn, ratingprofilesFn, actionsFn, actiontimingsFn, actiontriggersFn, accountactionsFn string) *CSVReader {
|
||||
func NewFileCSVReader(storage DataStorage, sep rune, destinationsFn, ratesFn, timingsFn, ratetimingsFn, ratingprofilesFn, actionsFn, actiontimingsFn, actiontriggersFn, accountactionsFn string) *CSVReader {
|
||||
c := new(CSVReader)
|
||||
c.sep = sep
|
||||
c.storage = storage
|
||||
c.actions = make(map[string][]*Action)
|
||||
c.actionsTimings = make(map[string][]*ActionTiming)
|
||||
c.actionsTriggers = make(map[string][]*ActionTrigger)
|
||||
@@ -66,7 +68,7 @@ func NewFileCSVReader(sep rune, destinationsFn, ratesFn, timingsFn, ratetimingsF
|
||||
}
|
||||
|
||||
func NewStringCSVReader(sep rune, destinationsFn, ratesFn, timingsFn, ratetimingsFn, ratingprofilesFn, actionsFn, actiontimingsFn, actiontriggersFn, accountactionsFn string) *CSVReader {
|
||||
c := NewFileCSVReader(sep, destinationsFn, ratesFn, timingsFn, ratetimingsFn, ratingprofilesFn, actionsFn, actiontimingsFn, actiontriggersFn, accountactionsFn)
|
||||
c := NewFileCSVReader(nil, sep, destinationsFn, ratesFn, timingsFn, ratetimingsFn, ratingprofilesFn, actionsFn, actiontimingsFn, actiontriggersFn, accountactionsFn)
|
||||
c.readerFunc = openStringCSVReader
|
||||
return c
|
||||
}
|
||||
@@ -89,7 +91,8 @@ func openStringCSVReader(data string, comma rune) (csvReader *csv.Reader, fp *os
|
||||
return
|
||||
}
|
||||
|
||||
func (csvr *CSVReader) WriteToDatabase(storage DataStorage, flush, verbose bool) (err error) {
|
||||
func (csvr *CSVReader) WriteToDatabase(flush, verbose bool) (err error) {
|
||||
storage := csvr.storage
|
||||
if storage == nil {
|
||||
return errors.New("No database connection!")
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
type DbReader struct {
|
||||
tpid string
|
||||
storDB DataStorage
|
||||
storage DataStorage
|
||||
actions map[string][]*Action
|
||||
actionsTimings map[string][]*ActionTiming
|
||||
actionsTriggers map[string][]*ActionTrigger
|
||||
@@ -40,16 +41,18 @@ type DbReader struct {
|
||||
ratingProfiles map[string]*RatingProfile
|
||||
}
|
||||
|
||||
func NewDbReader(storDB DataStorage, tpid string) *DbReader {
|
||||
func NewDbReader(storDB DataStorage, storage DataStorage, tpid string) *DbReader {
|
||||
c := new(DbReader)
|
||||
c.storDB = storDB
|
||||
c.storage = storage
|
||||
c.tpid = tpid
|
||||
c.activationPeriods = make(map[string]*ActivationPeriod)
|
||||
c.actionsTimings = make(map[string][]*ActionTiming)
|
||||
return c
|
||||
}
|
||||
|
||||
func (dbr *DbReader) WriteToDatabase(storage DataStorage, flush, verbose bool) (err error) {
|
||||
func (dbr *DbReader) WriteToDatabase(flush, verbose bool) (err error) {
|
||||
storage := dbr.storage
|
||||
if flush {
|
||||
storage.Flush()
|
||||
}
|
||||
@@ -223,9 +226,11 @@ func (dbr *DbReader) LoadRatingProfile(tag string) error {
|
||||
newAP := &ActivationPeriod{ActivationTime: at}
|
||||
newAP.Intervals = append(newAP.Intervals, ap.Intervals...)
|
||||
ratingProfile.AddActivationPeriodIfNotPresent(destination.Id, newAP)
|
||||
dbr.storage.SetDestination(destination)
|
||||
}
|
||||
}
|
||||
}
|
||||
dbr.storage.SetRatingProfile(ratingProfile)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -38,7 +38,7 @@ type TPLoader interface {
|
||||
LoadActionTimings() error
|
||||
LoadActionTriggers() error
|
||||
LoadAccountActions() error
|
||||
WriteToDatabase(DataStorage, bool, bool) error
|
||||
WriteToDatabase(bool, bool) error
|
||||
}
|
||||
|
||||
type Rate struct {
|
||||
|
||||
Reference in New Issue
Block a user