Make PartialPath be obtained from ProcessPath if opts field is missing

This commit is contained in:
ionutboangiu
2021-07-05 17:09:22 +03:00
committed by Dan Christian Bogos
parent 9e6fb6bccb
commit 15b90d23b7
2 changed files with 32 additions and 3 deletions

View File

@@ -693,6 +693,35 @@ func (cfg *CGRConfig) checkConfigSanity() error {
if !possibleReaderTypes.Has(rdr.Type) {
return fmt.Errorf("<%s> unsupported data type: %s for reader with ID: %s", utils.ERs, rdr.Type, rdr.ID)
}
var pAct string
if act, has := rdr.Opts[utils.PartialCacheActionOpt]; has { // check the action from opts
if pAct = utils.IfaceAsString(act); pAct != utils.MetaDumpToFile &&
pAct != utils.MetaNone &&
pAct != utils.MetaPostCDR {
return fmt.Errorf("<%s> wrong partial expiry action for reader with ID: %s", utils.ERs, rdr.ID)
}
}
if pAct != utils.MetaNone { // if is *none we do not process the evicted events
if fldSep, has := rdr.Opts[utils.PartialOrderFieldOpt]; has && // the field we order after must not be empty
utils.IfaceAsString(fldSep) == utils.EmptyString {
return fmt.Errorf("<%s> empty %s for reader with ID: %s", utils.ERs, utils.PartialOrderFieldOpt, rdr.ID)
}
} else if pAct == utils.MetaDumpToFile { // only if the action is *dump_to_file
path := rdr.ProcessedPath
if pathVal, has := rdr.Opts[utils.PartialPathOpt]; has { // the path from options needs to exists if overwriten by reader
path = utils.IfaceAsString(pathVal)
}
if _, err := os.Stat(utils.IfaceAsString(path)); err != nil && os.IsNotExist(err) {
return fmt.Errorf("<%s> nonexistent partial folder: %s for reader with ID: %s", utils.ERs, path, rdr.ID)
}
if fldSep, has := rdr.Opts[utils.PartialCSVFieldSepartorOpt]; has && // the separtor must not be empty
utils.IfaceAsString(fldSep) == utils.EmptyString {
return fmt.Errorf("<%s> empty %s for reader with ID: %s", utils.ERs, utils.PartialCSVFieldSepartorOpt, rdr.ID)
}
if len(rdr.CacheDumpFields) == 0 {
return fmt.Errorf("<%s> empty %s for reader with ID: %s", utils.ERs, utils.CacheDumpFieldsCfg, rdr.ID)
}
}
switch rdr.Type {
case utils.MetaFileCSV:
paths := []string{rdr.ProcessedPath, rdr.SourcePath}

View File

@@ -396,9 +396,9 @@ func (erS *ERService) onEvicted(id string, value interface{}) {
}
erS.rdrEvents <- &erEvent{cgrEvent: cgrEv, rdrCfg: eEvs.rdrCfg}
case utils.MetaDumpToFile: // apply the cacheDumpFields to the united events and write the record to file
var expPath string
if path, has := eEvs.rdrCfg.Opts[utils.PartialPathOpt]; has {
expPath = utils.IfaceAsString(path)
expPath := eEvs.rdrCfg.ProcessedPath
if pathVal, has := eEvs.rdrCfg.Opts[utils.PartialPathOpt]; has {
expPath = utils.IfaceAsString(pathVal)
}
if expPath == utils.EmptyString { // do not write the partial event to file
return